1>修改bool AppDelegate::applicationDidFinishLaunching()文件。
增加头文件
#include "luaProxy/tolua/luaopen_LuaProxy.h" |
增加以下内容:
// 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::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("ccbi.lua"); 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"TestAni.ccbi" local function menuCallbackClosePopup() --menuPopup:setVisible(false) local am = CCBAnimationManager:pickFromNode(n) am:runAnimations"scale" end local menuPopupItem = CCMenuItemImage:create("menu1.png", "menu1.png") menuPopupItem:setPosition(0, 0) menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) menuPopup = CCMenu:createWithItem(menuPopupItem) menuPopup:setPosition(400, 600) local s = CCScene:create() s:addChild(tolua.cast(n, "CCLayer")) 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> 运行结果
推荐阅读