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