Why need to call NSTimer again in this code?
Posted
by Tattat
on Stack Overflow
See other posts from Stack Overflow
or by Tattat
Published on 2010-03-28T15:52:42Z
Indexed on
2010/03/28
16:03 UTC
Read the original article
Hit count: 193
- (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.
© Stack Overflow or respective owner