我有CCN这样的CCN文件(因为我无法发布图片),
我想让rawImage成为mySprite的实例,而不是CCSprite,因为它是默认的。
所以,对于mySprite来说,加载器是这样的,
#include "mySprite.h"
class mySpriteLoader : public CCSpriteLoader{
public:
CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(mySpriteLoader, loader);
protected:
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(mySprite);
};
mySprite.h就是这个,
#include <iostream>
#include "cocos2d.h"
#include "cocos-ext.h"
using namespace cocos2d;
using namespace extension;
class mySprite : public CCSprite, public CCBMemberVariableAssigner {
public:
// CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(mySprite, create);
CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(mySprite, create);
bool onAssignCCBMemberVariable(CCObject* pTarget, const char* pMemberVariableName, CCNode* pNode){ return false; };
mySprite(){CCLog("init mySprite");};
};
我也注册了mySprite加载器,
m_loaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
m_loaderLibrary->registerCCNodeLoader("mySprite", mySpriteLoader::loader());
并在父CCLayer的方法中设置成员分配者
bool PanoController::onAssignCCBMemberVariable(CCObject* pTarget, const char* pMemberVariableName, CCNode* pNode){
CCLOG("%s panoController Assign",pMemberVariableName);
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "rawImage", mySprite*, m_rawImage);
}
仍然会抛出错误
Assertion failed: (m_rawImage), function onAssignCCBMemberVariable,
任何想法,请帮忙。它的工作正常,如果它的CCSprite,但mySprite没有。
答案 0 :(得分:0)
断言来自:
MEMBERVARIABLE = dynamic_cast<MEMBERVARIABLETYPE>(pNode);
CC_ASSERT(MEMBERVARIABLE);
节点的类节点是CCSprite而不是MySprite。 这意味着CocosBuilder无法设置自定义类MySprite。
您可以在AppDelegate.cpp注册节点,如下所示:
const char *pClassName = "MySprite"
cocos2d::extension::CCNodeLoader *pCCNodeLoader = MySpriteLoader::loader();
cocos2d::extension::CCNodeLoaderLibrary * pCCNodeLoaderLibrary = cocos2d::extension::CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
pCCNodeLoaderLibrary->registerCCNodeLoader(pClassName, pCCNodeLoader);