Note that there are some explanatory texts on larger screens.

plurals
  1. POThree second countdown in cocos2d
    text
    copied!<p>I am trying to have a 3 second countdown display when a level is beat in my game. So this is what I did:</p> <pre><code>-(void) gameSegmentBeat { [self pauseSchedulerAndActions]; // Overlay the game with an opaque background CCSprite *opaqueBG = [CCSprite spriteWithFile:@"background1.png"]; opaqueBG.position = screenCenter; [self addChild:opaqueBG z:10000]; // These are the 3 labels for the 3 seconds CCLabelTTF *three = [CCLabelTTF labelWithString:@"3" fontName:@"Helvetica" fontSize:100]; three.position = ccp(screenCenter.x, screenCenter.y); CCLabelTTF *two = [CCLabelTTF labelWithString:@"2" fontName:@"Helvetica" fontSize:100]; two.position = ccp(screenCenter.x, screenCenter.y); CCLabelTTF *one = [CCLabelTTF labelWithString:@"1" fontName:@"Helvetica" fontSize:100]; one.position = ccp(screenCenter.x, screenCenter.y); // Secondspast is specified in the update method secondspast = 0; if (secondspast == 1) { [self addChild:three z:10001]; } else if (secondspast == 2) { [self removeChild:three]; [self addChild:two z:10001]; } else if (secondspast == 3) { [self removeChild:two]; [self addChild:one z:10001]; } } </code></pre> <p>And the update:</p> <pre><code>framespast = 0; -(void)update:(ccTime)delta { framespast++; secondspast = framespast / 60; } </code></pre> <p>I called <code>gameSegmentBeat</code> in one of the methods I have not shown above... and I know it is being called because: 1. The <code>pauseSchedulerAndActions</code> is working and 2. The <code>CCSprite *opaqueBG</code> is being shown.</p> <p><strong>Also, something I should add is that if I move <code>[self addChild:three z:10001];</code> outside of the if statement that it is currently in, then the label shows up, but as soon as I move back into the if statement, it doesn't work...</strong></p> <p>I don't know why, but the labels are not being switched every second and so there is no countdown. </p> <p>Thanks in advance!</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