SDL: Why is my sprite flickering?
I will not post my full source code, as I have out a lot of work into it, and I don't really want to give away free code. However, I will try to outline my problem, and will send source code to those who seem to know what they are talking about and want to help.
Ok, here goes: After spending a good deal of time trying to figure out SDL's equivalent to layers, I discovered that my problem is unique. The sprite and background are both updated constantly, thus they appear to move. The background has no problems, not flickers, etc. However, the sprite flickers at a high annoying rate that makes it very hard to see. Here are my blits:
/* Scroll the the level background.. */
SDL_Flip( screen );
SDL_BlitSurface ( background, &pictureLocation, screen, NULL );
scrollPosition--;
pictureLocation.y = scrollPosition;
if ( scrollPosition <= 0 )
scrollPosition = 0;
/* Blit the player sprite to the screen. */
SDL_BlitSurface ( sprite, NULL, screen, &spriteLocation );
spriteLocation.y = spritePosition_y;
spriteLocation.x = spritePosition_x;
SDL_SetColorKey( sprite, SDL_SRCCOLORKEY, 0);
SDL_SetAlpha( sprite, SDL_SRCALPHA, 256 );
Sorry if they are a bit hard to read. Thanks in advance,
Max
Ok, here goes: After spending a good deal of time trying to figure out SDL's equivalent to layers, I discovered that my problem is unique. The sprite and background are both updated constantly, thus they appear to move. The background has no problems, not flickers, etc. However, the sprite flickers at a high annoying rate that makes it very hard to see. Here are my blits:
/* Scroll the the level background.. */
SDL_Flip( screen );
SDL_BlitSurface ( background, &pictureLocation, screen, NULL );
scrollPosition--;
pictureLocation.y = scrollPosition;
if ( scrollPosition <= 0 )
scrollPosition = 0;
/* Blit the player sprite to the screen. */
SDL_BlitSurface ( sprite, NULL, screen, &spriteLocation );
spriteLocation.y = spritePosition_y;
spriteLocation.x = spritePosition_x;
SDL_SetColorKey( sprite, SDL_SRCCOLORKEY, 0);
SDL_SetAlpha( sprite, SDL_SRCALPHA, 256 );
Sorry if they are a bit hard to read. Thanks in advance,
Max
just wondering, do you have double buffering enabled?
Yes do as Skyhawk asked and check for double buffering is enabled and if so are you swapping the buffers? Also I am not sure but think alpha channel usage in SDL is slow. You might want to move to OpenGL. Don't quote me on the alpha channel but sure I read it somewhere?
Quote:Originally posted by skyhawk
just wondering, do you have double buffering enabled?
Yes, and as far as alpha channels go, it has the same flicker without them, I added them just recently.
Quote:Originally posted by skyhawk
just wondering, do you have double buffering enabled?
You're right about the alphas being slow...
This might be your problem. Straight from the FAQ.
Quote:Q:
Why doesn't page flipping work?
A:
The SDL_DOUBLEBUF flag (and hence page flipping) is unsupported on Mac OS X. There is no support in the operating system for this feature.
Prior to version 1.2.6, SDL did not report an error when SDL_DOUBLEBUF was used, but instead returned a single-buffered surface. This resulted in various visual anomalies, depending on the application.
The only good alternatives are to use a software surface instead (SDL_SWSURFACE), or use OpenGL. With OpenGL, you'll have to write your own blitting engine, or borrow someone elses.
Update: SDL 1.2.6 has added experimental retrace-synchronized software "flipping". You access it by using SDL_DOUBLBUF|SDL_HWSURFACE|SDL_FULLSCREEN passed to SDL_SetVideoMode. SDL_Flip() will return immediately and the flip will be performed asynchronously in a separate thread.
belboz@cinci.rr.com
Quote:Originally posted by belboz
This might be your problem. Straight from the FAQ.
I have tried this, it still doesn't seem to work. I thought I'd add: the flicker _only_ happens when the sprite is scrolled over the background. Otherwise the sprite makes many copies of it's self; outside the back ground image that is.
Quote:Originally posted by Snibril
I have tried this, it still doesn't seem to work. I thought I'd add: the flicker _only_ happens when the sprite is scrolled over the background. Otherwise the sprite makes many copies of it's self; outside the back ground image that is.
Are you using the 1.2.6 version of SDL? I think 1.2.5 is the latest version they have online. Unless your building it from CVS or getting it from another source.
Your problem sounds to me like you are indeed not getting double buffering. You are working in a single buffer environment.
belboz@cinci.rr.com
Quote:Originally posted by belboz
Are you using the 1.2.6 version of SDL? I think 1.2.5 is the latest version they have online. Unless your building it from CVS or getting it from another source.
Your problem sounds to me like you are indeed not getting double buffering. You are working in a single buffer environment.
Yes, I agree with you. It's as if the images are both on the same 'layer' if you will. And they are fighting to be on top of one another... Anyway, what to do for me to get double buffering to work? It's paramount that I do so.
Well if your not using the latest, I would pull and build the latest CVS build. Maybe they have that work-around functional.
If not I don't see any real SDL solution. You might have to go the opengl route (you can still use SDL for audio, etc).
If not I don't see any real SDL solution. You might have to go the opengl route (you can still use SDL for audio, etc).
belboz@cinci.rr.com
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| GLUT Flickering | mikey | 5 | 3,134 |
May 28, 2009 12:06 PM Last Post: mikey |
|
| SDL Flickering | LWStrike | 2 | 2,922 |
Mar 31, 2006 11:50 PM Last Post: PowerMacX |
|

