I'm in the process of creating a 2D game in OpenGL ES for the iPhone. I'm calling my game loop using NSTimer at an interval of 0.002 (60 fps) with repeats set to 'NO' (I'm running the NSTimer again from within the function as recommended):
-(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];
}
This runs smoothly on my 3GS, however when I test this on a 2G the game runs much slower and sometimes I get the occasional blank frames. When I lower the interval to 0.033 (30 fps). It's too slow on the 3G.
I know there must be some way to get constistent playback on both devices. Doodle Jump seems to run smoothly and at the same framerate on both phones.