[SDL] Question about animation; erasing where my sprite has been
Edward Cullen
eac203 at ecs.soton.ac.uk
Mon Mar 3 14:09:36 PST 2008
Hi,
Basically, you have 2 strategies:
1) Clear screen and redraw everything.
2) Only redraw the bits that have changed.
Strategy 1 is the easiest, however, if you are working in 2D, with
limited PROCESSOR or memory BANDWIDTH, it is very wasteful, as you will
be moving many more blocks of memory about.
If you're working in 3D, you clearly don't have such limits, so you can
just wipe the screen.
Strategy 2 is much more complicated (as many optimisations are!);
Assuming you have a fixed background (no scrolling) you need to do this:
1. Draw the background once.
2. Decide where you are going to draw your sprite (do collision
detection etc.)
3. Save the portion of the background where you are going to put the
sprite into memory associated with the sprite (so that you can restore
it later).
4. Draw the sprite.
5. Remove the sprite by re-drawing the background from the backup.
6. Goto 2.
As I said, it matters what your target hardware is and whether you have
scrolling etc.
Eddy
Michael Sullivan wrote:
> I've drawn my sprite in it's original position. I move it to a new
> location and redraw the screen. The sprite is drawn in then new
> position, but also still shows in the old position. How to fix this?
> I'm using double-buffering, if that matters. The full code of my
> project in it's current state can be found at
> http://www.espersunited.com/~michael/needhelp/ourrpg/ if reference to it
> is necessary...
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
More information about the SDL
mailing list