iphone - Three second countdown in cocos2d -


i trying have 3 second countdown display when level beat in game. did:

-(void) gamesegmentbeat {     [self pauseschedulerandactions];      // overlay game opaque background     ccsprite *opaquebg = [ccsprite spritewithfile:@"background1.png"];     opaquebg.position = screencenter;     [self addchild:opaquebg z:10000];      // these 3 labels 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 specified in 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];     } } 

and update:

framespast = 0;  -(void)update:(cctime)delta {       framespast++;       secondspast = framespast / 60; } 

i called gamesegmentbeat in 1 of methods have not shown above... , know being called because: 1. pauseschedulerandactions working , 2. ccsprite *opaquebg being shown.

also, should add if move [self addchild:three z:10001]; outside of if statement in, label shows up, move if statement, doesn't work...

i don't know why, labels not being switched every second , there no countdown.

thanks in advance!

you possibly use timed execution blocks 1, 2 , 3 second delay in execution:

dispatch_time_t countdowntime1 = dispatch_time(dispatch_time_now, (int64_t)(1 * nsec_per_sec)); dispatch_after(countdowntime1, dispatch_get_main_queue(), ^(void){      [self addchild:three z:10001];  });  dispatch_time_t countdowntime2 = dispatch_time(dispatch_time_now, (int64_t)(2 * nsec_per_sec)); dispatch_after(countdowntime2, dispatch_get_main_queue(), ^(void){      [self removechild:three];     [self addchild:two z:10001];  });  dispatch_time_t countdowntime3 = dispatch_time(dispatch_time_now, (int64_t)(3 * nsec_per_sec)); dispatch_after(countdowntime3, dispatch_get_main_queue(), ^(void){      [self removechild:two];     [self addchild:one z:10001];  }); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -