我想知道我是否以正确的方式实现固定的时间步长游戏循环,这样我就能在程序中实现帧速率独立移动。
...
double start = 0, end = 0;
double deltaTime = 0.0;
double milliSecs = (1000.0 / TARGET_FPS) / 1000.0; //60 FPS
while (!quit) {
start = SDL_GetTicks() / 1000.0;
deltaTime += (double)(start - end) / milliSecs;
end = start;
//Update/Draw Stuff
while (deltaTime >= 1.0) {
//Update Stuff
deltaTime -= 1.0;
}
SDL_SetRenderDrawBlendMode(Renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255);
SDL_RenderClear(Renderer);
Tile::drawTileMap(Renderer);
Object::drawObjectArray(Renderer);
SDL_RenderPresent(Renderer);
}
...
提前谢谢。