3.cocos2d-x中通过lua脚本载入并使用ccbi 下载本文

内容发布更新时间 : 2024/11/17 7:37:24星期一 下面是文章的全部内容请认真阅读。

1>修改boolAppDelegate::applicationDidFinishLaunching()文件。

增加头文件

#include\

增加以下内容:

// register lua engine CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); CCLuaStack *pStack = pEngine->getLuaStack(); lua_State *tolua_s = pStack->getLuaState(); tolua_extensions_ccb_open(tolua_s); luaopen_LuaProxy(tolua_s); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) pStack = pEngine->getLuaStack(); tolua_s = pStack->getLuaState(); tolua_web_socket_open(tolua_s); #endif std::stringpath = CCFileUtils::sharedFileUtils()->fullPathForFilename(\); pEngine->executeScriptFile(path.c_str()); 删除以下内容: // create a scene. it's an autorelease object CCScene *pScene = HelloWorld::scene(); // run pDirector->runWithScene(pScene); 2>增加ccbi.lua脚本 local proxy = LuaProxy:create() local n = proxy:readCCBFromFile\ local function menuCallbackClosePopup() --menuPopup:setVisible(false) local am = CCBAnimationManager:pickFromNode(n) am:runAnimations\end local menuPopupItem = CCMenuItemImage:create(\menuPopupItem:setPosition(0, 0) menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) menuPopup = CCMenu:createWithItem(menuPopupItem) menuPopup:setPosition(400, 600) local s = CCScene:create() s:addChild(tolua.cast(n, \CCDirector:sharedDirector():runWithScene(s) s:addChild(menuPopup) proxy:handleAnimationComplate(am, function(am, timelineName, hnd) -- do something after timeline complate end)

2>添加附加依赖项 libcurl_imp.lib

3>添加LuaProxy-master支持

3.1将LuaProxy目录拷贝到Classes目录下:

3.2在vs中添加LuaProxy目录中所有文件

4>运行结果