実行中のタイマーもすべて正常に機能していました。しかし、奇妙な問題に遭遇したとき、cocos2d シーンを再構築する必要がありました。これで、NSTimer を起動できなくなりました。以下の BonusTimetimer は一度も起動されません。
以下はコードです。
BonusTimeTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(CountTimeBonus:) userInfo:nil repeats:YES];
// (lately i added the line below, but it does not help)
[[NSRunLoop mainRunLoop] addTimer:BonusTimeTimer forMode:NSDefaultRunLoopMode];
-(void)CountTimeBonus:(NSTimer *) sender {
NSLog (@"Method -> Countimebonus");
if ( (scoreTotal + 37) < TargetScore){
scoreTotal = scoreTotal + 37;
TimeBonus = TimeBonus-37;
NSString *level_timebonus = [NSString stringWithFormat:@"%d", TimeBonus];
[labelTimeBonus setString: level_timebonus];
NSString *scorestr = [NSString stringWithFormat:@"%d", scoreTotal];
[labelMainScore setString: scorestr];
[[SimpleAudioEngine sharedEngine] playEffect:@"light_switch_.mp3"];
}
else {
// add the Last few points and finish BonusTimer
scoreTotal = scoreTotal + TimeBonus;
TimeBonus=0;
NSString *level_timebonus = [NSString stringWithFormat:@"%d", timebonusgrayed];
[labelTimeBonus setString: @"" ];
[labelTimeBonusGrayed setString: level_timebonus];
NSString *scorestr = [NSString stringWithFormat:@"%d", scoreTotal];
[labelMainScore setString: scorestr];
[[SimpleAudioEngine sharedEngine] playEffect:@"light_switch_.mp3"] ;
[BonusTimeTimer invalidate];
BonusTimeTimer = nil;
timeBonusisdone = true;
timeBonusisactive = false;
}
}