新手请教!如何建立一个炸弹类继承CCSprite,  新继承类用create() 和 createWithSpriteFrameName()读取图片?

新手请教!如何建立一个炸弹类继承CCSprite, 新继承类用create() 和 createWithSpriteFrameName()读取图片?

我准备新定义了一个炸弹类,继承CCSprite ,此炸弹还带有几个子精灵(光环,闪光,冲击波等)。
建立这个炸弹类的目的,是用CCArray 存储 10个炸弹, 玩家可以放置多个炸弹,用定时器 检测多个炸弹的冲击波。
但是,自己建立的新类是无法直接使用create() 和 createWithSpriteFrames()函数读取图片的。
我查询了下资料,按照create()方法重写了个函数,就可以直接读取文件了。(见:static gamesprite* gameSpriteWithFile(const char * pszFileName);)
现在想了解,如何重写createWithSpriteFrames()函数,才能读取精灵帧缓存???
感谢。

====create()方法重写gameSpriteWithFile读图片文件。成功。
.h定义
class gamesprite : public cocos2d::CCSprite
{
public:
gamesprite(void);
~gamesprite(void);
static gamesprite* gameSpriteWithFile(const char * pszFileName);
};

.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”);

==========
createWithSpriteFileName方法重写 gameWithSpriteFileName,失败,运行报错。

.h

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 x86_64:
“org_bomb::org_bomb()”, referenced from:
org_bomb::gameWithSpriteFrame(cocos2d::CCSpriteFrame*) in HelloWorldScene.o
org_bomb::gameWithSpriteFrameName(char const*) in HelloWorldScene.o

干嘛继承CCSprite,新建一个Bomb类,里面添加一个Sprite成员,如果一定要用CCArray作为容器,就继承Ref,CCNode及其子类是渲染用的,而你的炸弹是游戏的一个逻辑对象,别什么玩意拿来就用继承,现在用的爽,后面有罪受的

除非要修改渲染,不然没必要继承CCSprite,能用组合就不要用继承!!!

仔细分析一下这段话:
我准备新定义了一个炸弹类,继承CCSprite ,此炸弹还带有几个子精灵(光环,闪光,冲击波等)。[从这句话的解读,就更不能继承CCSprite了,为什么呢,因为如果光环要处于炸弹的下层,然而光环又是炸弹的子节点,这时候岂不是很尴尬???明显应该继承CCNode,然后这些东西都是该Node的子节点]
建立这个炸弹类的目的,是用CCArray 存储 10个炸弹, 玩家可以放置多个炸弹,用定时器 检测多个炸弹的冲击波。[这句话就更奇怪了,炸弹类明显是一个炸弹,怎么能是10个炸弹呢??根本就不懂是什么意思,炸弹类当且仅当只能是一个炸弹,放10个炸弹的是炸弹池类,跟炸弹类完全不是一个东西,在炸弹池类中使用定时器,检测里面所有的炸弹,这算是基本的一个处理了](当然如果当游戏做的大了之后,炸弹池是不能作为定时器检测炸弹的,池的概念是容器,容器是不能做动态自身改变的,必须由另一个类管理该池的改变与变化,当然作为小游戏,还是可以接受的)

能否给个例子?
我直接继承CCNode,测试启动后暴机。

.h
class _bombNode: public cocos2d::CCNode
{
public:
_bombNode(void);
~_bombNode(void);
CCSprite* _bomb;
CCSprite* _child;
CCSprite* _halo;
CCSprite* _sparkle;

};

class HelloWorld : public cocos2d::CCLayer
{
public:
_bombNode* _bombFamily;

.cpp
_bombFamily->_bomb = CCSprite::create(“Icon-72.png”);

运行启动场景后,出错。