如何在createWithSpriteFrameName中使用动态精灵名称?(How to use dynamic sprite names with createWithSpriteFrameNam

编程入门 行业动态 更新时间:2024-10-17 09:49:21
如何在createWithSpriteFrameName中使用动态精灵名称?(How to use dynamic sprite names with createWithSpriteFrameName?)

我想根据Cocos2d-x和C ++中的一些动态变量更改精灵图像,所以我尝试这样的东西,但是有一个错误。 这可能是一种正确的方法吗? 问候。

auto name = String::createWithFormat("x%i.png", _destroyedUnits); auto combo = Sprite::createWithSpriteFrameName(name);

我已经看到createWithSpriteFrameName接受C ++ basic_string,而不是Cocos String,所以我创建了这样的输出是“名字是:??”

int _destroyedUnits = 20; std::string intToString = std::to_string(_destroyedUnits); std::string name("x" + intToString); CCLOG("The name is: %s", name);

什么是正确的方法呢? 问候。

I want to change a sprite image according to some dynamic variable in Cocos2d-x and C++, so I'm, trying something like this but there is an error. What could it be a right way to do it?. Greetings.

auto name = String::createWithFormat("x%i.png", _destroyedUnits); auto combo = Sprite::createWithSpriteFrameName(name);

I've seen that createWithSpriteFrameName accept a C++ basic_string, not a Cocos String, so I created like this and the output is "The name is: ??"

int _destroyedUnits = 20; std::string intToString = std::to_string(_destroyedUnits); std::string name("x" + intToString); CCLOG("The name is: %s", name);

What's the right way to do it? Greetings.

最满意答案

正如cocos2d-x测试中所建议的那样,正确的方法是使用sprintf,你可以像这样使用它:

char tmp[30]; sprintf(tmp,"x%i.png", _destroyedUnits); std::string atlasName = tmp; auto combo = Sprite::createWithSpriteFrameName(atlasName.c_str());

As suggested in cocos2d-x tests, the right way is to use sprintf, you can use it like this:

char tmp[30]; sprintf(tmp,"x%i.png", _destroyedUnits); std::string atlasName = tmp; auto combo = Sprite::createWithSpriteFrameName(atlasName.c_str());

更多推荐

本文发布于:2023-08-05 23:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1440933.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   精灵   动态   如何在   createWithSpriteFrameName

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!