iPhone用のOpenGL ESで2Dゲームを作成中です。繰り返しを「NO」に設定して、0.002 (60 fps) の間隔で NSTimer を使用してゲーム ループを呼び出しています (推奨どおりに関数内から NSTimer を再度実行しています)。
-(void)gameLoop:(id)sender {
double currTime=(double)CACurrentMediaTime();
m_FPS_framesThisSecond++;
float timeThisSecond=currTime-m_FPS_lastSecondStart;
if (timeThisSecond>1.0f) {
m_FPS=m_FPS_framesThisSecond;
m_FPS_framesThisSecond=0;
m_FPS_lastSecondStart=currTime;
}
[game update];
[game render];
//Continue the loop
[NSTimer scheduledTimerWithTimeInterval:0.002 target:self selector:@selector(gameLoop:) userInfo:nil repeats:NO];
}
これは私の 3GS ではスムーズに動作しますが、2G でこれをテストすると、ゲームの動作が非常に遅くなり、時折空白のフレームが表示されることがあります。間隔を 0.033 (30 fps) に下げると。3Gでは遅すぎる。
両方のデバイスで一貫した再生を得るには何らかの方法が必要であることはわかっています。Doodle Jump は、両方のスマートフォンでスムーズに同じフレームレートで実行されているようです。