local tempProxy = CCBProxy:create()
local startLayer = tempProxy:readCCBFromFile("StartLayer.ccbi")
startlayer可以使用,没问题,但是在用过tempProxy加载startLayer里的控件,label等子node时
解决的方案如下
local tempProxy = CCBProxy:create()
local proxy = tempProxy:readCCBFromFile("StartLayer.ccbi")
local startLayer = tolua.cast(proxy,"CCBProxy")
修改后 通过startlayer来读取子node就对了
startLayer:handleButtonEvent(btn,
function( s,e )
end
,0)
LuaEventHandler * LuaEventHandler::create(lua_State *l){
LuaEventHandler *h = new LuaEventHandler();
h->_lua = l == NULL? luaStateForEngine() : l;
h->autorelease();
return h;
}
LuaEventHandler * LuaEventHandler::create(lua_State *l){
LuaEventHandler *h = new LuaEventHandler();
h->_lua = luaStateForEngine();//l == NULL? luaStateForEngine() : l;
h->autorelease();
return h;
}
===============
题外,原代码CCBProxy在新的cocos2dx里有些不兼容,会出现nodeLoader 注册问题
assert(ccNodeLoadersIterator != this->mCCNodeLoaders.end());
class CCBProxyLoader: public CCLayerLoader {
public:
virtual bool init(){return true;}
CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(CCBProxyLoader, loader);
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(CCBProxy);
};
在CCBProxy.cpp里
CCScene * CCBProxy::sceneReadCCBFromFile(const char *f, float resolutionScale)
{
//assert(f && strlen(f) > 0, "File name must not be null or empty string.");
CCNodeLoaderLibrary * lib = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
//lib->registerCCNodeLoader("CCParticleSystemQuad", ProxyPSQLoader::loader());
CCBReader * reader = new CCBReader(lib);
reader->autorelease();
#if COCOS2D_VERSION < 0x00020100
reader->hasScriptingOwner = true;
#endif
lib->registerCCNodeLoader("CCBProxy", CCBProxyLoader::loader());
CCScene *node = reader->createSceneWithNodeGraphFromFile(f);
CCBAnimationManager *m = reader->getAnimationManager();
node->setUserObject(m);
return node;
}