试图建立一个与CCLabelTTF作为它的一部分是串在cocos2d-X℃的整数++ [英] Trying to set up a CCLabelTTF with an integer as part of it's string in Cocos2d-X C++

查看:199
本文介绍了试图建立一个与CCLabelTTF作为它的一部分是串在cocos2d-X℃的整数++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,在Objective-C与Cocos2D中,我会使用一个带有的NSMutableString格式把一个变量(分数)为一个字符串。我会采取该字符串,并使用CCLabel将其放置在屏幕上。

使用的Cocos2D-X,我无法找到一种方式来获得这样的结果。一个简单的例子将是巨大的。谢谢!


解决方案

  INT评分= 35;
时差= 0.03;
的char *名称=迈克尔;
字符文本[256];
的sprintf(文字,名称%S,时间%.2f,得分为%d,名称,时间,得分);
CCLabelTTF *标签= CCLabelTTF :: labelWithString(文字,宋体,20);
这 - >的addChild(标签);

So in Objective-C with Cocos2d, I'd use a NSMutableString with format to put a variable (score) into a string. I'd take that string and use a CCLabel to place it on the screen.

Using Cocos2D-x, I'm having trouble finding a way to get this result. A simple example would be great. Thanks!

解决方案

int score = 35;
float time = 0.03;
char* name = "Michael";
char text[256];
sprintf(text,"name is %s, time is %.2f, score is %d", name, time, score);
CCLabelTTF* label = CCLabelTTF::labelWithString(text,"Arial",20);
this->addChild(label);

这篇关于试图建立一个与CCLabelTTF作为它的一部分是串在cocos2d-X℃的整数++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆