0

http://www.raywenderlich.com/25736/how-to-make-a-simple-iphone-game-with-cocos2d-2-x-tutorialのcocos2d ゲーム チュートリアルを使用しました。スコアは増加しますが、以前のスコアは削除されず、新しいスコアは以前のスコアのラベルの上に追加されます

コード:

CGSize winSize = [[CCDirector sharedDirector] winSize];
CCLabelTTF * label1 = [CCLabelTTF labelWithString:@"_monsterdestroyed" fontName:@"Arial" fontSize:32];
score=score + 2;

[label1 setString:[NSString stringWithFormat:@"%d",score]];

label1.color = ccc3(0,0,0);
label1.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:label1];
4

1 に答える 1

0

更新のたびに label1 ラベルを追加して、更新メソッドでこれらすべてを行っていると思います。おそらく、スコア label1 の .h ファイルに iVar が必要であり、次のように init で初期化します。

.h で

CCLabelTTF *label1;

メートルで

-(id) init {
    if (self = [super init]) {
        // your existing code, add the following
        CGSize winSize = [[CCDirector sharedDirector] winSize];

        label1 = [CCLabelTTF labelWithString:@"0" fontName:@"Arial" fontSize:32];
        label1.color = ccc3(0,0,0);
        label1.position = ccp(winSize.width/2, winSize.height/2);
        [self addChild:label1];  
   }     
 }


 // where you update the score
 score = score + 2;
 [label1 setSting:[NSString stringWithFormat:"%i", score];
于 2013-05-06T10:23:12.577 に答える