Advertisement Jump to content


This topic is now archived and is closed to further replies.


2D Sprite Engine

This topic is 5951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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); = 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

Share this post

Link to post
Share on other sites
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.


10x10 sprite at 0,0

moves 6 pixels south

You would need to clip:

0,0 through 10,16 from the background

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!