while( quit == -1 )
{
// Did user quit?
while( SDL_PollEvent( &sdlEvent ) )
if( sdlEvent.type == SDL_QUIT )
quit = 1;
// Apply surfaces
ApplySurface(0, 0, background, screen);
// Flip the screen
if( SDL_Flip( screen ) == -1 )
return 1;
++numFrames;
sprintf( fpsbuff, "FPS: %.0f", (numFrames/(float)(SDL_GetTicks() - startTime))*1000);
SDL_WM_SetCaption(fpsbuff, NULL);
// Regulate FPS
currTime = SDL_GetTicks();
if( oldTime != 0 )
if( currTime - oldTime < 60 )
SDL_Delay(60 - (currTime-oldTime));
oldTime = currTime;
}
我试图将FPS锁定为60,我的一些计算是错误的吗?
将FPS锁定为值的任何其他智能方法?
答案 0 :(得分:4)
60 FPS~ = 16.7 ms / f。将参数修复为SDL_Delay
。
BTW2:60FPS与SDL?您将需要硬件加速,我担心SDL本身不会为您提供。考虑SDL + OpenGL或SFML。
答案 1 :(得分:0)
这可能是因为你的系统无法跟上60 fps。仅仅因为你告诉它并不意味着它能够。