を使用してCCLabelTTF
、プレーヤーのスコアを画面に表示しています。ただし、スコア ラベルを更新するために呼び出す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で、スコア ラベルを開始します。
- (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];
}