我一生都无法弄清楚为什么会发生这种情况。我有一个从 CCLayer 派生的类。我在初始化类时像这样安排方法调用
//create an update method for keeping track of how long its been since an animation has played
[self schedule:@selector(playIdleAnimation:)];
方法是
//an update method that will play an idle animation after a random period of idleness
-(void) playIdleAnimation:(ccTime) dt {
//if the user isn't playing an animation, increment the time since last animation variable
if ([bodySprite numberOfRunningActions] == 0) {
timeSinceLastAnimation += (float)dt;
//now check to see if we have surpassed the time set to cause an idle animation
if (timeSinceLastAnimation > (arc4random() %14) + 8) {
//reset the cooldown timer
timeSinceLastAnimation = 0;
[bodySprite stopAllActions];
//play the idle animation
//[bodySprite runAction:[CCAnimate actionWithAnimation:waitAnimation restoreOriginalFrame:NO]];
NSLog(@"PLAYING IDLE ANIMATION");
}
}
//player is currently playing animation so reset the time since last animation
else
timeSinceLastAnimation = 0;
}
但是,当我运行程序时,控制台语句显示每个冷却时间都通过了两次条件
012-06-29 09:52:57.667 测试游戏[5193:707] 播放空闲动画
2012-06-29 09:52:57.701 测试游戏[5193:707] 播放空闲动画
2012-06-29 09:53:05.750 测试游戏[5193:707] 播放空闲动画
2012-06-29 09:53:05.851 测试游戏[5193:707] 播放空闲动画
我正在尝试修复当我播放完空闲动画时游戏崩溃的错误,我确信这与它有关。