- 使用C++的格式化方法
// 第一种方式 char *s; sprintf(s, "%d",10);
- 使用cocos的StringUtils类format函数
// 第二种方式 std::string s1 = StringUtils::format("%d",10);
- 使用cocos的Value函数
// 第三种方式 std::string s2 = Value(10).asString();
- 使用cocos的StringUtils类toString函数
// 第四种方式 std::string s3 = StringUtils::toString(10);
- 使用字体
auto label1 = Label::createWithTTF(s, "fonts/arial.ttf", 40);
label1->setPosition(Vec2(visibleSize.width/3, visibleSize.height/2));
this->addChild(label1);