Sprite and Bitmap frustration....

Started by
2 comments, last by shdaga 23 years, 8 months ago
Ok, I need some advice from some of you veterans out there. Here goes. Im running in to some problems trying to load a srite with some animation frames.. Heres the lowdown, in my sprite struct I have an array of offscreen surfaces of size equal to the number of animation frames the sprite has. The surfaces are 16x16x16(WidthxHeightxColordepth). Now lets say that I have successfully loaded a .bmp file that is 640x480x16 and have also blitted(sp?) it to an offscreen directdraw7 surface. I basically want to blit an area of the afore mentioned offscreen surface to each one of the sprites frame surfaces (essentially loading the sprite with the animation frames.) Heres what i have been doing so far and obviously this is not the correct way to do it...
    
int LoadSpriteFrame(SpritePtr sprite, LPDIRECTDRAWSURFACE7 source, int frame, int cell_x, int cell_y, int mode)
{
	
RECT source_rect;
	
if(mode == CELL_MODE)
{
    cell_x = cell_x*(sprite->width+1)+1;
    cell_y = cell_y*(sprite->height=1)+1;
}

source_rect.left  = cell_x;
source_rect.top   = cell_y;
source_rect.right = (source_rect.left + sprite ->width)-1;
source_rect.bottom= (source_rect.top  + sprite ->height)-1;

if((sprite->frames[frame])->Blt(NULL,source, &source_rect,       (DDBLT_WAIT | DDBLT_KEYSRC),NULL) != DD_OK)
	return(0);

return(1);
}    
Is this the way to go about extracting animation frames from a surface.. or am i forgeting something. Anyway I've spent two days trying to figure out a way to solve this simply. Any help would be apreciated. --bah! who needs a signature?! Edited by - shdaga on 8/23/00 3:52:22 AM
Here's a new dance everyone can do, do the Kirby:<(*.*<) <(^.^)> (>*.*)> <(^.^)> <(*.*<) (>^.^)>
Advertisement
I''m not a C++ guru, but I can say that it looks fine. I''m using VB for my game, but I don''t do such procedure loadsprite with all parameters. I''m doing the following:

Dim MySurf as DirectDrawSurface7
Dim MyRect as RECT
dim MySurfDesc as ddsddesc


Then:
''res=1024*768
Sub DrawMap()

myrect.left=frameindexx*32
myrect.right=.left+32
myrect.top=frameindexy*32
myrect.bottom=.top+32

for x=0 to 32
for y=0 to 24
backsurface.bltfast x*32,y*32,mysurf,m,yrect,blt_wait or srckey
next
next
frameindexx=frameindexx+1
if frameindexx= 32 ''say 32 frames on x THEN
framindexx=0
frameindexy=frameindexy+1
endif
if frameindexy=10 then
frameindexy=0
endif

end sub
That''s the simplest representation of how I do that. You method will work, especially because it''s a sprite engine(use of sprite parameters such as int height, width and so on)

That''s it.
Well, actaully I was wondering why this doesnt seem to work in directX7. I mean I have no problem blitting a 640x480x16 bitmap to the backbuffer, but if I try to extract a small rectangle from a surface and blit it to another offscreen surface (say 16x16), it doesnt seem to work...Anybody care to shed some light on what they do when it comes to making animatable sprites in directx7? thanks

-out-

--bah! who needs a signature?!
Here's a new dance everyone can do, do the Kirby:<(*.*<) <(^.^)> (>*.*)> <(^.^)> <(*.*<) (>^.^)>
I thikn it''s a mistake to make one surface per frame of every sprite you''re gonna have. Every surface you create comes with some overhead and takes up a litle more mem than the actual surface dimensions.

What I thikn you would want to do is have ONE surface per sprite and load up the entire tileset as your sprite, then when you blit you get the source rect according to the frame #
sumthin like:
src.left = (frame%num_frames_per_line)*sprite_width;
src.top = (frame/num_frames_per_line)*sprite_height;
src.right = src.left+sprite_width;
src.bottom = src.top+sprite_height;

and then blit to your offscreen buffer or whatever.
num_frames_per_line is set to how many frames you have on one horizontal line in your tileset. Say your frames are 32x32 and the tileset is 320x200 for example, then num_frames_per_line would be equal to 10.

However, if you want t omake it simple, make all your tilesets with the frames aligned vertically (one frames per row), then you can take out those extra calculations, not that they make a difference in speed at all, just easier to understand.

BTW, ALL of what i have said here is what is said and done in the Donuts example in the dx sdk, and in many of the other 2d examples they give you. Tkae a look at them, they''re there for a reason

ByteMe95::~ByteMe95()
Cerebrum Software
ByteMe95::~ByteMe95()My S(h)ite

This topic is closed to new replies.

Advertisement