开发者社区> 问答> 正文

如何在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];

展开
收起
a123456678 2016-07-20 17:48:25 2204 0
1 条回答
写回答
取消 提交回答
  • 你应该为场景添加相应的标签,如果想用初始化的方法,可以编写:

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

    CCLabelTTF *scorelabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"score: %d",score] fontName:@"Verdana-Bold" fontSize:18.0f];
    2019-07-17 19:59:08
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载