【发布时间】:2013-10-07 05:26:02
【问题描述】:
我试图在我的游戏中通过一个关卡时显示 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 语句,它不起作用...
我不知道为什么,但标签并不是每秒都在切换,所以没有倒计时。
提前致谢!
【问题讨论】:
-
gameSegmentBeat 在哪里调用?我猜它被调用过一次。
-
我更新了问题。
标签: iphone ios objective-c cocos2d-iphone