Ваш int countTime = 20;
объявляет себя каждый раз равным 20. Кроме того, ваш цикл while будет уменьшать countTimer так быстро, как система сможет обновить CCLabel. Если вы пытаетесь создать реальный таймер, вы хотите, чтобы он уменьшался ТОЛЬКО при вызове countDown:
. Не во время цикла.
Попробуйте это:
@interface MyScene : CCLayer
{
CCLabel *_text;
}
@property (nonatomic, retain) int countTime;
@end
@implementation MyScene
@synthesize countTime = _countTime;
-(id) init {
if( (self=[super init] )) {
CCSprite *background = [CCSprite spriteWithFile:@"backgame.png"];
CGSize size = [[CCDirector sharedDirector] winSize];
[background setPosition:ccp(size.width/2, size.height/2)];
[self addChild: background];
_countTime = 20;
_text = [CCLabel labelWithString:[NSString stringWithFormat:@"%i", self.countTime]
fontName:@"BallsoOnTheRampage" fontSize:46];
text.position = ccp(160,455);
text.color = ccYELLOW;
[self addChild:_text];
[self schedule:@selector(countDown:) interval:0.5f];// 0.5second intervals
}
return self;
}
-(void)countDown:(ccTime)delta {
self.countTime--;
[_text setString:[NSString stringWithFormat:@"%i", self.countTime]];
if (self.countTime <= 0) {
[self unschedule:@selector(countDown:)];
}
}
@end