Hi. i’m making Vertical Shoot’em-up game by using SDL.
Framerate is regulated by my created code. (16~17 ms per frame, 60 frames per second)
However, Game animation is not smooth. (Shaking and choppy.)
for example, when Player character move right to left,
the character goes to left, sometimes the character seems to go right. (the character is shaking.)
also the Bullet Animation is not smooth, sometimes choppy.
(are the problems ‘Tearing’??)
so, i checked the my game logic code about X, Y Position. is not the problem.
when i Set framerate to 1FPS (1 frame per second), the animation is not choppy.
please help me…
the codes are the part of my Game Project.
below is screen making code.
if (bFullScreen == true)
{
pSurface = SDL_SetVideoMode(width, height, bpp, SDL_ANYFORMAT | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
}
else
{
pSurface = SDL_SetVideoMode(width, height, bpp, SDL_ANYFORMAT | SDL_HWSURFACE | SDL_DOUBLEBUF);
}
below is the main logic of Draw Sprites and Regulating Framerate.
static int iFrameCount = 0;
static Uint32 iFrameOldTime;
static Uint32 iAccumulatedTime = 0;
while (bRunning)
{
iFrameOldTime = SDL_GetTicks();
if (bRunning == false)
{
return;
}
SDL_FillRect(pSurface, pSurface->clip_rect, SDL_MapRGB(pSurface->format, 0x00, 0x00, 0x00);
//draw the sprites. (player, enemy, bullets, …) below is example.
SDL_BlitSurface(ExampleSurface, NULL, pSurface, ExampleRect);
SDL_Flip(pSurface);
iFrameCount++;
double fTempFrameRate = 999.0;
Uint32 iTick;
while (fTempFrameRate > 60.0)
{
iTick = SDL_GetTicks();
iFrameTime = iTick - iFrameOldTime;
fTempFrameRate = (double)(iFrameCount) / (double)(iAccumulatedTime + iFrameTime) / 1000.0);
}
iAccumulatedTime = iAccumulatedTime + iFrameTime;
fFrameRate = fTempFrameRate;
if (iAccumulatedTime >= 500)
{
iAccumulatedTime = 0;
iFrameCount = 0;
}
}