ios - 如何在Cocos2d 3.0版本中添加得分标签?
大家讲道理
大家讲道理 2017-04-17 12:04:13
[iOS讨论组]

我为得分的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

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
ringa_lee

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

[self addChild:scorelabel];

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

CCLabelTTF *scorelabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"score: %d",score] fontName:@"Verdana-Bold" fontSize:18.0f];
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号