2D Sprite Engine

Started by
1 comment, last by mrhodes 21 years, 6 months ago
Hey everyone, sorry to post this without searching, the search engine is down Anyway... my problem is this, I am writing a little 2D game engine to use to hopefully make some cool little games with I can load bitmaps, I have a mouse pointer that can be loaded, etc.... right now I am stuck on the sprite code. as of now it works, as long as the screen is cleared each frame... What I want to do is make it so that when the Draw function is called a background snapshot is taken where the sprite will be drawn, and then the sprite is drawn... next frame, replace the background, and repeat... I wrote all this out on paper, and coded it, and edited several times and I always seem to get a bit of garbage following my character as he moves across the screen... I''ll post my code for now, perhaps you may see whats wrong... SpriteUnder is suposed to do the house keeping work of backing up and replacing what is being written over. And SpriteDraw just simply draws the given frame to the backbuffer... void TE3DSprite::SpriteUnder(void) { if(bIsBackup) g_display.pBackbuffer->BltFast(x_old, y_old, pUnderSprite, NULL, DDBLTFAST_WAIT); backup.top = y; backup.left = x; backup.bottom = y + CellHeight + 1; backup.right = x + CellWidth + 1; pUnderSprite->BltFast(0, 0, g_display.pBackbuffer, &backup, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); x_old = x; y_old = y; bIsBackup = TRUE; } void TE3DSprite::SpriteDraw(int frame) { // Add clipping code to this... g_display.pBackbuffer->BltFast(x, y, pSurface, &pCells[frame - 1], DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT); } // void TE3DSprite::SpriteDraw(int frame) Well, if any one has any ideas, please help... I''m not sure what to do with this now.. And also if someone can tell me how to isolate the code in this post, I''ll come back and edit that too... Thanks a lot, Mike
Michael RhodesTiger Studios Web Designhttp://tigerstudios.net
Advertisement
Make sure that your "snapshot" of the background includes all of the area that the sprite was originally in as well as the area the new sprite is in.

ie:

10x10 sprite at 0,0

moves 6 pixels south

You would need to clip:

0,0 through 10,16 from the background
Are you using double buffering ? Dirty rectangle methods (that''s the official name of what you''re doing) on double buffered displays are slightly more complex than what you described. Essentially, your SpriteUnder function will write the sprite background back to a different buffer than it originated from ! The result is a kind of trail behind each sprite, where the background is shifted.

/ Yann

This topic is closed to new replies.

Advertisement