我正在使用 aCCLabelTTF
在屏幕上显示玩家的得分。但是,当我调用setString
更新分数标签时,它不会更新(因此它始终保持在 0)。
这是我的代码:
在Player.m中,我启动了一个新的 PlayerHUD 对象:
- (id) init{
if (self = [super init]){
playerHUD = [[PlayerHUD alloc] loadPlayerInterface];
[self addChild:playerHUD z:UPLAYER_Z];
}
return self;
}
在PlayerHUD.m中,我启动了 Score Label :
- (id) loadPlayerInterface{
if (self = [super init]){
score = 0;
//Score Label
lblScore = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%d", score] fontName:@"pixel" fontSize:24];
[self addChild:lblScore z:1000];
}
return self;
}
仍在PlayerHUD.m中,这是我的更新功能:
- (void) updateScore:(NSInteger)_newscore{
score = _newscore;
[lblScore setString:[NSString stringWithFormat:@"%d", score]];
}
而且,在Player.m中,我在这里调用更新函数:
- (void) addScore{
int scoreToAdd = 50
score += scoreToAdd;
NSLog(@"Score:%d", score);
[playerHUD updateScore:score];
}