Note that there are some explanatory texts on larger screens.

plurals
  1. POTimer condition being passed twice, using cocos2d scheduler
    text
    copied!<p>I can't for the life of my work out why this is happening. I have in a class derived from CCLayer. I am scheduling a method call like so when initialising the class</p> <pre><code>//create an update method for keeping track of how long its been since an animation has played [self schedule:@selector(playIdleAnimation:)]; </code></pre> <p>And the method is</p> <pre><code>//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 &gt; (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; } </code></pre> <p>But yet, when I go to run the program the console statements show the condition is being passed twice each cooldown</p> <p>012-06-29 09:52:57.667 Test Game[5193:707] PLAYING IDLE ANIMATION</p> <p>2012-06-29 09:52:57.701 Test Game[5193:707] PLAYING IDLE ANIMATION</p> <p>2012-06-29 09:53:05.750 Test Game[5193:707] PLAYING IDLE ANIMATION</p> <p>2012-06-29 09:53:05.851 Test Game[5193:707] PLAYING IDLE ANIMATION</p> <p>I am trying to fix a bug where the game crashes when I finish playing the idle animation, and I'm certain this has something to do with it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload