当前位置: 代码迷 >> 综合 >> cocos2dx int 转 string的几种方法
  详细解决方案

cocos2dx int 转 string的几种方法

热度:59   发布时间:2024-01-24 05:39:01.0
  • 使用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);

  相关解决方案