- (void) applicationDidFinishLaunching:(UIApplication *)application
{
//set up main loop
[NSTimer scheduledTimerWithTimeInterval:0.033
target:self selector:@selector(gameLoop:) userInfo:nil repeats:NO];
//create instance of the first GameState
[self doStateChange:[gsMain class]];
}
- (void) gameLoop: (id) sender
{
[((GameState*)viewController.view) Update];
[((GameState*)viewController.view) Render];
[NSTimer scheduledTimerWithTimeInterval:0.033 target:self
selector:@selector(gameLoop:) userInfo:nil repeats:NO];
}
This code is from a iPhone game development book. I don’t know why the gameLoop method need to call the NSTimer again? in the applicationDidFinishLaunching, it set the NSTimer to do, why don’t let it do every 0.033s, why add the same NSTimer code in the gameLoop method? thz.
Update: Sorry, my question should be clarify… …Why the code don’t just simply call repeats: YES?
You could certainly get away with turning repeats:YES on:
Actually, you would be better off this way, because the timing would be more consistent – the code you have listed here only starts the new timer after the frame has been calculated, which will give you irregular frames if those calls take varying amounts of time.