I’m learning game devel with SDL and I have a basic doubt.
What’s the best method to do sprite basic animation ?
- repaint entire background each loop and paint sprites on it ?
- maintain background safe, doing backups from part of background
for each sprite painted ?
If you have lots of sprites, or (obviously) if you’re scrolling the
screen as well, the former is the way to go. It’s also much more
reliable (or rather, a lot easier to get right) if you want to
support various kinds of displays. Most importantly, h/w page
flipping displays complicate the second approach a bit.
Either way, if you’re going for the second approach, keep in mind that
reading from the display surface is normally (*) very expensive if
it’s a hardware surface. This applies for glSDL as well, BTW. Most
OpenGL implementations seem to fall back to software blitting when
reading or writing pixels from/to the display buffer.
You’re much better off removing sprites by other means than keeping
backups. (Besides, you have to make sure the screen is in the right
state before you grab those backsave rects.)
One way is to simply redraw the area of the background covered by each
sprite you want to remove. (That is, render tiles from the map, or
whatever.) This is usually simple and effective, and doesn’t require
any extra memory for backsave. If you have very expensive background
rendering (such as multilayered tiles with blending and stuff, “real
time” raytraced backgrounds or whatever), you’re probably better off
using some other method. Such as…
…keeping an extra back buffer for background rendering only. Do
whatever you need to render the background into that buffer, and then
blit from there to initialize the screen. (You’ll have to do the
latter twice for a h/w page flipping double buffered display.) Then
keep the back buffer for sprite removal through plain blitting.
(*) The only exception is integrated chipsets that use a system
RAM area as VRAM. Those don’t have PCI or AGP between the
CPU and VRAM, so the 386 + VGA class bottleneck is avoided.
Atari ST and TT, Commodore Amiga (using OCS, ECS or AGA) and
most older consoles work in similar ways. I believe the XBox
has the same issue as any PC, but I don’t know about the PS2.
The second method is a lot confunsing to implement.
That goes for pretty much everything but the plain brute force
Anyone knows some tutorial about this, preferably using SDL, that
shows me different methods, and what I can expect from each one and
how can I implement them ?
Well, I’m planning to hack a demo + documentation, covering the most
common methods, how to deal with h/w page flipping etc. Can’t do it
right now, though. (Work, Kobo Deluxe, Audiality, Real Life etc.)
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
— http://olofson.net — http://www.reologica.se —On Tuesday 24 June 2003 06.28, H. G. Fischer wrote: