2
我希望我的游戏能以固定的FPS在我家附近的多台计算机上运行。我有一个简单的问题:我如何调试我当前的FPS调整后调整/调试当前FPS吗?
我正在调节我的FPS像这样:
SDL_Init(SDL_INIT_EVERYTHING);
const unsigned FPS = 20;
Uint32 start = SDL_GetTicks(); // How much time (milliseconds) has passed after SDL_Init was called.
while (true)
{
start = SDL_GetTicks();
if (1000/FPS > SDL_GetTicks() - start)
SDL_Delay(1000/FPS - (SDL_GetTicks() - start)); // Delays program in milliseconds
我觉得应该去调整自己的FPS。问题是,我如何获得当前的fps?
我试图
std::stringstream fps;
fps << 1000/FPS - (SDL_GetTicks() - start);
SDL_WM_SetCaption(fps.str().c_str(), NULL); // Set the window caption
和
fps << start/1000; // and vice versa
但他们都不给我我想要的。
看过这个吗? http://gafferongames.com/game-physics/fix-your-timestep/ – 2012-01-14 08:28:02
不,但它看起来非常有趣。我会读这个。提前致谢。 – evolon696 2012-01-14 08:28:57