Archived

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

maintain the background while moving objects?

This topic is 5620 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

Dear All, I am learning graphics programming and try some simple animation technique using C, djgpp. I have drawn some planets encircling the sun by blitz method. Procedure: 1.clear virtual screen 2*800x600// 16-bit color 2.draw object on vscreen 3. wait for retrace 4. transfer vscreen to real screen thru bank switching steps 4.5) clear virtual screen 5. increment object position 6. go to (2). But I want to put some background scene, not just the moving objects on the black background cause by clearing the whole screen. What are the steps, algorithm to create a background, clear only the old position of object and patch up the space with the background, put the object new position on top of the background. Thank you. Patrick [edited by - patrick_chm on July 23, 2002 11:58:14 AM]

Share this post


Link to post
Share on other sites
Well, depends. If you have LOTS of sprites that change, you could just keep the background in a buffer and blit (memcpy, possibly line-by-line) it all to the main buffer instead of clearing. If you really only want to update the overdrawn parts, you will need to keep up some form of "dirty rect" scheme. Dirty rects are rectangular parts of a buffer/sprite which are known to need updating. This means you save the coordinates of every sprite you blit and blit that part of the background image to the back buffer. If you don''t know what I mean, either ask or (better) do a google search on dirty rect, I''m sure there is some info to be found. A dirty rect scheme is no advantage if you''re drawing a LOT, especially with overdraw, as you''ll spend more time copying the same parts of the screen back and forth than actually drawing the scene, so it''s often better to just blit the whole background.
A variation of this is to have a buffer for various parts of the scene and doing the same with that, like, you have a tiled landscape and don''t want to update it every frame because it always stays the same - just have a seperate buffer in memory.

- JQ
Full Speed Games. Period.

Share this post


Link to post
Share on other sites