我想通过使用cocos2d开发一个iPhone应用程序。我使用“scheduledTimerWithTimeInterval”来调用一个称为固定时间间隔的方法。但现在时间间隔逐渐增加。为此,时间逐渐缓慢。 这里是我的代码:“scheduledTimerWithTimeInterval:”在cocos2d中的问题?
- (void) methodTime: (id) sender{
NSTimer *rat =[NSTimer scheduledTimerWithTimeInterval:(.5) target:self selector:@selector(rotation:) userInfo:nil repeats:YES];
}
- (void) rotation:(NSTimer *)theTimer{
NSLog(@"I m # %i", i);
i=i+10; // Here , i is a global int variable.
i=i % 1440;
if(i==0){
[theTimer invalidate];
}
else {
int rotationNum=i;
Sprite *sp = [Sprite spriteWithFile: @"1.png"];
sp.position=cpv(220,180.5);
sp.rotation=rotationNum;
[self add:sp];
}
}