[迁移]cocos2d-x 2.1.4 CocosBuilder-3.0-alpha5 lua
生活随笔
收集整理的這篇文章主要介紹了
[迁移]cocos2d-x 2.1.4 CocosBuilder-3.0-alpha5 lua
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
聲明:因網易博客將關閉,移到此
cocos2d-x 2.1.4中提供了ccb的lua實現,下面是一個實現
打開cocosbuilder,File–>New–>Porject…
創建項目名字是ccb_project
我們就直接用默認生成的ccbi吧,這里是MainScene.ccbi
把需要的幾個資源復制到Resources資源目錄的ccb目錄里面(clickme-down.png,clickme.png,MainScene.ccbi)
把TestLua例子中找到的CCBReaderLoad.lua放到Resources資源目錄
下面就是controller.lua代碼了
function main_test()collectgarbage("setpause", 100)collectgarbage("setstepmul", 5000)require("luaScript/CCBReaderLoad");CCFileUtils:sharedFileUtils():addSearchPath("ccb");local MainSceneLayer = MainSceneLayer or {}ccb["MainScene"] = MainSceneLayerlocal MainSceneLayerOwner = MainSceneLayerOwner or {}ccb["MainSceneLayerOwner"] = MainSceneLayerOwnerlocal function onCCControlButtonClicked()cclog("cc")if nil ~= MainSceneLayer["helloLabel"] thenlocal ccLabelTTF = tolua.cast(MainSceneLayer["helloLabel"],"CCLabelTTF")if nil ~= ccLabelTTF thenccLabelTTF:setString("click button")endendendMainSceneLayer["onPressButton"] = onCCControlButtonClicked;local layer_root = CCLayer:create();local proxy = CCBProxy:create()local node = CCBReaderLoad("ccb/MainScene.ccbi",proxy,true,"MainSceneLayerOwner")local layer = tolua.cast(node,"CCLayer")if nil ~= MainSceneLayer["helloLabel"] thencclog("aaaaaaaaaa");local ccLabelTTF = tolua.cast(MainSceneLayer["helloLabel"],"CCLabelTTF")if nil ~= ccLabelTTF thenccLabelTTF:setString("ccb/MainScene.ccbi")endendlayer_root:addChild(layer);----------------------------------------------------------- 主場景local scene_main = CCScene:create();scene_main:addChild(layer_root);local curScene = CCDirector:sharedDirector():getRunningScene();if curScene ~= nil thenCCDirector:sharedDirector():replaceScene(scene_main);elseCCDirector:sharedDirector():runWithScene(scene_main);end endxpcall(main_test, __G__TRACKBACK__)總結
以上是生活随笔為你收集整理的[迁移]cocos2d-x 2.1.4 CocosBuilder-3.0-alpha5 lua的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BT种子文件信息库-Torrentinf
- 下一篇: 户外lisp导向牌如何安装_详细图解丨|