Flicker problem

Hi there!
I?m coding a 2D graphics engine and currently have the screen display a
tilemap that has some of its tiles animated (such as water tiles moving to
simulate water waves). Then the screen displays a controllable sprite that
moves when you use the arrow keys. So far so good, but the sprite character
keeps flickering more than I?d want and it?s really bothering me (the
tilemap rendering works fine). What should I do?
I tried setting different flags such as SDL_HWSURFACE|SDL_SWSURFACE in
conjuction with SDL_DOUBLEBUF, without double-buffering, or just one of
them, but the flickering remains the same. Also, I don?t know a proper value
to set to SDL_Delay() just before(or should it be after?) SDL_Flip(). And
the weirdest thing is, when I don?t put SDL_Delay() between the map
rendering command and the sprite character rendering command, the character
doesn?t appear, as if it is being covered too quickly by the loop.

Here is a part of my main loop:

while(done == false)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
done = true;
break;
case SDL_KEYUP:
{
princeArthur->SetState(STILL);
princeArthur->sprite->SetCurrentAnim(STOP);
canWalk = false;

          break;
                   }
       case SDL_KEYDOWN:
       {
                     if(event.key.keysym.sym == SDLK_ESCAPE)
                       done = true;
         else if(event.key.keysym.sym == SDLK_RETURN)
                    {
          princeArthur->SetState(STILL);
                      princeArthur->sprite->SetCurrentAnim(STOP);
                       canWalk = false;
        }
                   else
      {
                     if(event.key.keysym.sym == SDLK_DOWN)
	            princeArthur->sprite->SetFacing(DOWN);
	         else if(event.key.keysym.sym == SDLK_UP)
	            princeArthur->sprite->SetFacing(UP);
	         else if(event.key.keysym.sym == SDLK_RIGHT)
	            princeArthur->sprite->SetFacing(RIGHT);
	         else if(event.key.keysym.sym == SDLK_LEFT)
	            princeArthur->sprite->SetFacing(LEFT);

	         canWalk = true;
          }
          break;
       }
    }
 }

 if(canWalk == true)
 {
    princeArthur->SetState(WALKING);

    if(princeArthur->sprite->GetFacing() == DOWN)
       princeArthur->sprite->SetCurrentAnim(FRONT_WALK);
    else if(princeArthur->sprite->GetFacing() == UP)
       princeArthur->sprite->SetCurrentAnim(BACK_WALK);
    else if(princeArthur->sprite->GetFacing() == RIGHT)
       princeArthur->sprite->SetCurrentAnim(RIGHT_WALK);
    else if(princeArthur->sprite->GetFacing() == LEFT)
       princeArthur->sprite->SetCurrentAnim(LEFT_WALK);
 }

 map->Render();//This is the rendering command for the tilemap
 SDL_Delay(1);
 princeArthur->Act(false); //This is the rendering command for the 

sprite
SDL_Delay(100);
SDL_Flip(screen);

}

Well Hotmail messed up my pasted code?? But I guess it is more or less
understandable.

Thanks in advance,
Carol._________________________________________________________________
Insta-le agora o Windows Live Messenger
http://get.live.com/messenger/overview

Hi there!
I?m coding a 2D graphics engine and currently have the screen display a
tilemap that has some of its tiles animated (such as water tiles moving to
simulate water waves). Then the screen displays a controllable sprite that
moves when you use the arrow keys. So far so good, but the sprite character
keeps flickering more than I?d want and it?s really bothering me (the
tilemap rendering works fine).

Do any of your other functions call SDL_UpdateRect, _UpdateRects or _Flip?
If so, take them away, and only let it happen here, in your mail loop:

> > map->Render();//This is the rendering command for the tilemap > SDL_Delay(1); > princeArthur->Act(false); //This is the rendering command for the > sprite > SDL_Delay(100); > SDL_Flip(screen);

Good luck!

PS - You’ll probably want to make SDL_Delay() take a dynamically-generated
value, depending on how much time has been spent since the last time you
rendered the screen, so that your game stays at approx. the same framerate
(fps) no matter how fast a system you run it on. :)On Fri, Aug 18, 2006 at 09:48:20PM +0000, Carolina Sim?es Gomes wrote:


-bill!
bill at newbreedsoftware.com
http://www.newbreedsoftware.com/