当我的游戏中一个关卡被击败时,我试图显示 3 秒倒计时。所以这就是我所做的:
-(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];
}
}
和更新:
framespast = 0;
-(void)update:(ccTime)delta {
framespast++;
secondspast = framespast / 60;
}
我调用gameSegmentBeat
了上面没有显示的一种方法......我知道它被调用是因为:1.pauseSchedulerAndActions
正在工作,2.CCSprite *opaqueBG
正在显示。
另外,我应该补充的是,如果我移到[self addChild:three z:10001];
它当前所在的 if 语句之外,那么标签就会显示出来,但是一旦我移回 if 语句,它就不起作用了......
我不知道为什么,但是标签并不是每秒都在切换,所以没有倒计时。
提前致谢!