Help with sprites

Hello to everyone, I a newbie of this list and SDL libs. I’m working with
sprites and I use double buffer and SDL_Flip function. While moving my
sprite (grabbing key event) I have a bad flickering effect. How can I solve
this problem???
Thanks a lot and sorry for my english.
Bye.

Andrea.

Do you flip only once per frame? (ie, after erasing the old copy of the
sprite and then redrawing) Or are you flipping after each draw AND each
erase? If so, that’ll do it. :slight_smile:

-bill!On Wed, Dec 12, 2001 at 02:09:11PM +0100, Andrea Massioli wrote:

Hello to everyone, I a newbie of this list and SDL libs. I’m working with
sprites and I use double buffer and SDL_Flip function. While moving my
sprite (grabbing key event) I have a bad flickering effect. How can I solve
this problem???
Thanks a lot and sorry for my english.
Bye.

Hello to everyone, I a newbie of this list and SDL libs. I’m working
with

sprites and I use double buffer and SDL_Flip function. While moving my
sprite (grabbing key event) I have a bad flickering effect. How can I
solve

this problem???
Thanks a lot and sorry for my english.
Bye.

Do you flip only once per frame? (ie, after erasing the old copy of the
sprite and then redrawing) Or are you flipping after each draw AND each
erase? If so, that’ll do it. :slight_smile:

-bill!


I flip only once a frame but I see that i have that problem while moving my
sprite pressing a keyboard key, so grabbing the keydown event and setting
the repet mode on.
Thanks a lot.
Bye, Andrea.> On Wed, Dec 12, 2001 at 02:09:11PM +0100, Andrea Massioli wrote:

Hello to everyone, I a newbie of this list and SDL libs. I’m working
with sprites and I use double buffer and SDL_Flip function. While
moving my sprite (grabbing key event) I have a bad flickering effect.
How can I solve this problem???

Easy solution:

Redraw the whole screen every frame, to completely eliminate any
dependencies on what may be in the buffer you’re about to update. That
is, render the background and then the sprites, drawing overeverything.
If you’re going to do full screen scrolling or other full screen
animation, this is the easiest and also fastest way to do it. (Short of
getting brushing up that good old hardware scrolling knowledge, and get
it to work with some modern API, that is… Now that’s messy stuff,
though!)

Hard solution:

Keep track of both video buffers when updating the sprites. The problem
is that what you get as the back buffer after you SDL_FlipSurface() is
not the previous frame you rendered, but the one before that!

One easy way that works well if the sprites aren’t moving too many pixels
between each update is setting the clip rect to an area that covers the
two last locations of the sprite, as well as the new location, and then
just repaint that area completely.

Thanks a lot and sorry for my english.

No problem! :slight_smile: (At least I think I understand what your problem is. :wink:

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Wednesday 12 December 2001 14:09, Andrea Massioli wrote: