Hi. i wrote my problem yesterday.
(http://forums.libsdl.org/viewtopic.php?p=34129&sid=cb132bd5df1f1b10cfbc6245501fa686)
I changed Framerate Regulation code ‘while loop’ to ‘FPS Manager’.
but Sprite moving is still Jittering.
Though I removed the code about Framerate, but Still Jittering.
below is My Code From My Project includes more detail sprite draw code.
I process the sprite x,y position ‘double’. ( (int) casted.)
My Development Environment is MS Visual Studio 2010, Windows 7.------------------------------------------------------------------------------------------
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;
FPSmanager MyFPS; SDL_initFramerate(&MyFPS); SDL_setFramerate(&MyFPS,60);
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.
if (iCurrentFrameTime == iFrameChangeInterval)
{
iCurrentFrame++;
if (iCurrentFrame == iMaxFrame)
{
iCurrentFrame = 0;
}
iCurrentFrameTime = 0;
}
else
{
iCurrentFrameTime++;
}
SDL_Rect rect1;
rect1.x = iCurrentFrame * width; //‘width’, ‘height’ is User-defined Sprite-part scale.
rect1.y = 0;
rect1.w = width;
rect1.h = height;
SDL_Rect rect2;
rect2.x = (int)dest_x; //‘dest_x’, ‘dest_y’ is double variables. but, Though I set them ‘int’, (e.g. int dest_x, int dest_y) the problem not solved.
rect2.y = (int)dest_y;
SDL_BlitSurface(ExampleSurface, &rect1, pSurface, &rect2); //‘pSurface’ is the game screen.
SDL_Flip(pSurface); iFrameCount++;
SDL_framerateDelay(&MyFPS);iFrameTime =
SDL_GetTicks() - iFrameOldTime;
iAccumulatedTime = iAccumulatedTime + iFrameTime; fFrameRate = (double)(iFrameCount) / (double)(iAccumulatedTime) / 1000.0); if (iAccumulatedTime >= 500) { iAccumulatedTime = 0; iFrameCount = 0; } }