gpt4 book ai didi

android - [Cocos2dx]如何为自定义 Sprite 设置图片?

转载 作者:行者123 更新时间:2023-11-28 07:21:05 25 4
gpt4 key购买 nike

我正在使用 Cocos2dx 2.1.4 开发游戏,想创建一个自定义的 Sprite 类。但是,我不知道如何为它设置图像。像 CCSprite::create("xxx.png")initWithFile("xx.png") 这样的东西。

怎么做?是否需要覆盖自定义 Sprite 类中的initWithFile

最佳答案

您应该重写您要使用的 CCSprite 的 create 方法和 onEnter onExit 方法,例如:

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
}

关于android - [Cocos2dx]如何为自定义 Sprite 设置图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19467522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com