0

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

怎么做?我需要initWithFile在自定义精灵类中覆盖吗?

4

1 回答 1

1

你应该重写你想要使用的 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
}
于 2013-10-20T07:40:19.517 回答