[Cocos2dx]如何为自定义精灵设置图像
[Cocos2dx]How to set image for self-defined sprite?
我正在使用Cocos2dx 2.1.4开发游戏,并希望创建一个自定义的精灵类。但是,我不知道如何为它设置图像。像CCSprite::create("xxx.png")
或initWithFile("xx.png")
之类的东西.
怎么办?我需要覆盖自定义精灵类中的initWithFile
吗?
你应该覆盖CCSprite的创建方法,你应该使用,并在Enter上退出方法,如:
MySprite* MySprite::create(const char *pszFileName)
{
MySprite *pobSprite = new MySprite();
if (pobSprite && pobSprite->initWithFile(pszFileName))
{
pobSprite->autorelease();
return pobSprite;
}
CC_SAFE_DELETE(pobSprite);
return NULL;
}
void MySprite::onEnter()
{
// Register touch delegate
}
void MySprite::onExit()
{
// Unregister touch delegate
}
相关文章:
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- C++自定义比较函数
- 如何比较自定义类的std::变体
- std::设置自定义比较器
- 如何正确实现和访问运算符的各种自定义枚举器
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 自定义先决条件对移动分配运算符有效吗
- 使用VS Code和CMake Tools运行自定义命令
- 如何创建从Maya(或类似程序)到虚幻引擎的自定义数据导出插件
- std::ranges::elements_view,用于自定义类似元组的数据
- 跟随整数索引列表的自定义类迭代器
- 参数化自定义CMake工具链
- 使用自定义比较函数使用std::sort()对矢量字符串进行排序时出现问题
- 如何在自定义类中启用'auto loops'?
- 使用QJsEngine在Qt中注册自定义类型
- Qt自定义QPush按钮未显示在布局上
- 自定义对象的dlib序列化在gcc中失败
- 自定义创建QFuture
- [Cocos2dx]如何为自定义精灵设置图像