cocos2d 在 sprite 上画一些东西

cocos2d draw something on top of the sprite

我对 cocos2d 很陌生。我已经阅读了精灵和动作的基本概念。我在创建精灵(来自图像文件)之后想知道。我想动态地在精灵上画一些数字,这可行吗?或者从图像创建后不能在精灵上绘制任何东西?

提前感谢您的回复。

使用 Render Texture 绘制 sprite,然后您可以将其添加为 sprite 的子项。

如果您想在 Sprite 上显示文本或数字,您可以添加一个 UIText 小部件作为子部件。

auto sprite = Sprite::create("image.png");
addChild(sprite);


auto text = Text::create();
text->setString("Test");
// Position the text in the center of the sprite
text->setPosition(Vec2(sprite->getContentSize().width*.5,
                       sprite->getContentSize().height*.5));
sprite->addChild(text);