如何在Cocos2d 3.0版本中添加得分标签?

我为得分的int设置为:

int score=0;

我知道如何设置增加得分标签,但不太清楚怎样把它展示出来:
在我使用的代码中,但我觉得下述代码肯定存在问题:

CCLabelTTF *scorelabel = [CCLabelTTF labelWithString:@"score" fontName:@"Verdana-Bold" fontSize:18.0f];
int score=0;
CCLabelTTF *scorelabel = [CCLabelTTF labelWithString:@"score" fontName:@"Verdana-Bold" fontSize:18.0f];
[self addChild:scorelabel];<pre><code>有谁能帮我解决下这个问题吗?
我现在用的代码是:
</code></pre>int score=0;
CCLabelTTF *scorelabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"score: %d",score] fontName:@"Verdana-Bold" fontSize:18.0f];  **The warning**
scorelabel.positionType = CCPositionTypeNormalized;
scorelabel.position = ccp(0.0f, 0.0f);
[self addChild:scorelabel];<pre><code>backButton
</code></pre>CCButton *backButton = [CCButton buttonWithTitle:@"[ Menu ]" fontName:@"Verdana-Bold" fontSize:18.0f];
backButton.positionType = CCPositionTypeNormalized;
backButton.position = ccp(0.85f, 0.95f); // Top Right of screen
[backButton setTarget:self selector:@selector(onBackClicked:)];
[self addChild:backButton];

原问题:Adding Score Label Cocos2d 3.0

阅读 3.2k
1 个回答

答:connor
你应该为场景添加相应的标签,如果想用初始化的方法,可以编写:

[self addChild:scorelabel];

当然,你的得分标签只是包括文本分数(text "score"),而不是实际的得分。如果想要表现出实际得分,需要将标签的形式设定为:

CCLabelTTF *scorelabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"score: %d",score] fontName:@"Verdana-Bold" fontSize:18.0f];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题