请教如何定义一个新类继承CCSprite,用帧缓存的方式读取图片,是否需重写 createWithSpriteFrame模式。

希望定义一个炸弹类,继承CCSprite;

炸弹精灵类同时还有子精灵halo,子精灵sparkle,子精灵_shockwave。

创建这个炸弹类,如何用 帧缓存读取的方式实现读取图片?

头文件定义:
class org_bomb : public cocos2d::CCSprite
{
public:
org_bomb();
~org_bomb();

static org_bomb* gameWithSpriteFrame(CCSpriteFrame* pSpriteFrame);
static org_bomb* gameWithSpriteFrameName(const char *pszSpriteFrameName);
bool isvisible;
CCSprite* halo;
CCSprite* sparkle;
CCSprite* _shockWave;

};

CPP文件:
org_bomb* org_bomb::gameWithSpriteFrame(CCSpriteFrame *pSpriteFrame)
{
org_bomb *pobSprite = new org_bomb();
if (pSpriteFrame && pobSprite && pobSprite->initWithSpriteFrame(pSpriteFrame))
{
pobSprite->autorelease();
return pobSprite;
}
CC_SAFE_DELETE(pobSprite);
return NULL;
}

org_bomb* org_bomb::gameWithSpriteFrameName(const char* pszSpriteFrameName){
CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pszSpriteFrameName);

#if COCOS2D_DEBUG > 0
char msg = {0};
sprintf(msg, “Invalid spriteFrameName: %s”, pszSpriteFrameName);
CCAssert(pFrame != NULL, msg);
#endif

return org_bomb::gameWithSpriteFrame(pFrame);

}

运行直接报错:
Undefined symbols for architecture i386:
“org_bomb::org_bomb()”, referenced from:
org_bomb::gameWithSpriteFrame(cocos2d::CCSpriteFrame*) in HelloWorldScene.o
org_bomb::gameWithSpriteFrameName(char const*) in HelloWorldScene.o

现在实现了重写工厂方法直接读取文件。但是不知道怎么重写帧缓存的方法读取.plist内文件。
create方式
.h定义
class gamesprite : public cocos2d::CCSprite
{
public:
gamesprite(void);
~gamesprite(void);
static gamesprite* gameSpriteWithFile(const char * pszFileName);

//virtual void setPosition(const CCPoint&pos);

};

.cpp实现
gamesprite* gamesprite::gameSpriteWithFile( const char pszFileName) {
gamesprite
sprite = new gamesprite();
if(sprite&&sprite->initWithFile(pszFileName))
{
sprite->autorelease();
return sprite;
}
CC_SAFE_DELETE(sprite);
return NULL;
}

_player1 = gamesprite::gameSpriteWithFile(“Icon-72.png”);

新手入门,请高手帮忙看下如何改成读取.plist实现?

没看懂你在问什么,是读取plist将它生成一个包含整个plist所有CCSpriteFrame的CCAnimation,还是读取plist中的一个CCSpriteFrame生成Sprite。前者通过
framesArray = CCArray::create(); CCSpriteFrame* frame = NULL;
int index = 1;
do
{
frame = cache->spriteFrameByName(CCString::createWithFormat("%s_%d.png",Keyname,index++)->getCString());
if (frame == NULL)
{
break;
}

    framesArray->addObject(frame);
} while (true);

CCAnimation* animation = CCAnimation::createWithSpriteFrames(framesArray);

可以得到
后者是将 CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();cache->addSpriteFramesWithFile(plistName,picName);和你上面自己的方法组合即可

我准备新定义了一个炸弹类,继承CCSprite ,此炸弹还带有几个子精灵(光环,闪光,冲击波等)。

建立这个炸弹类的目的,是用CCArray 存储 10个炸弹, 玩家可以放置多个炸弹,用定时器 检测多个炸弹的冲击波。

但是,自己建立的新类是无法直接使用create() 和 createWithSpriteFrames()函数读取图片的。

我查询了下资料,按照create()方法重写了个函数,就可以直接读取文件了。(见:static gamesprite* gameSpriteWithFile(const char * pszFileName);)

现在想了解,如何重写createWithSpriteFrames()函数,才能读取精灵帧缓存???

感谢。

跪求不要继承CCSprite,没有这种设计!!!!!!!!!!!!

继承Node就可以了
所有你需要效果什么的都添加到这个Node里