[SDL] SDL "Sprite" handling...
Gordon Henderson
gordon+sdl at drogon.net
Wed Apr 18 07:18:33 PDT 2012
Hi,
I'm looking to add some sprite handling to my little project - ie. a small
bitmap image that I can move over (on top of) the screen according to
program control.
I just want to make sure I'm not being too naive and not missing something
obvious!
Looking at this:
http://gamedevgeek.com/tutorials/moving-sprites-with-sdl/
it seems straightforward, however that program re-draws the entire screen
every frame. I want my sprites to "float" on-top of any background without
having to re-draw the background, so .... For each sprite, If I
blit the screen rectangle (same x,y,size as sprite) into a temp. buffer,
blit the sprite to the screen,
update/flip,
blit the screen temp. buffer back to the screen
lather rise, repeat with new sprite position and so on. Each sprite
needing a Surface to hold the sprite and another the same size to hold the
copy of the background.
I'm fairly sure that will work, but it will be doing a lot of memory moves
(even if rather small, say 20x20 pixels) and as long as I draw then /erase
them in the same order (or erase in reverse order) then the background
ought to stay untouched and sprites can happily move on-top of each other.
Although its will be doing a lot less memory moves than the example in
that website above!
I have seen SDL-Layer, but in its absence is the above OK, or am I
missing a trick?
Cheers,
Gordon
More information about the SDL
mailing list