I may be wrong, it’s been a while since I did this, but you should use the SDL_SetColorKey BEFORE converting the surface to the display format, so your code should look like this:
levelbg_bmp = SDL_LoadBMP(“image.bmp”);
SDL_SetColorKey(levelbg_bmp,
SDL_SRCCOLORKEY|SDL_RLEACCEL,
SDL_MapRGB(levelbg->format,255,0,255));
levelbg = SDL_DisplayFormat(levelbg_bmp);
SDL_FreeSurface(levelbg_bmp);
Also note that if your image is REALLY a background, ie, there nothing behind it, you SHOULD NOT use a color key on it, even on hardware accelerated surfaces it will take a lot of processing power and make your scrool looks bad. It’s good practice, if you have multi-layered scroll, to have two surfaces, one for colorkeyed blocks and other for opaque blocks, so you waste no processing power.
Another point, at least on Windows it goes like that, you may not need to use SDL_Delay to “wait”. When using SDL_Flip on a fullscreen hardware double buffered surface, it will wait for the vertical retrace and hence give plenty of time for other apps to do their job. Of course, windowed games doesn’t have access to that (HINT: if your game is running on a window, it WILL look worse than in hardware full screen in Windows). Of course, it’s good practice to check on which situation you are:
if(!fullscreen_hw_surface)
SDL_Delay(10);
It can be made better by trying to calculate the time spent to draw the screen and force a fixed frame rate. For 50fps (1000/50=20), it will be like that:
while(playing)
{
Uint32 start = SDL_GetTicks();
// Draw everything to screen and flips it
Uint32 end=SDL_GetTicks();
if( end-start<20)
SDL_Delay(20-(end-start));
}
Another good practice, if you want your animation looks the same no when you can’t achieve a constant frame rate, is to keep track of time when animating elements, not track of frame numbers. It’s a bit more complicated when you have to pause and you have to consider a maximum time slip for you animation until you start to slow it down to make your game playable.
Well, if something is confusing, let me know (also, if I confused something, let me also know :P).
Paulo