[迁移]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"] = MainSceneLayer

    local MainSceneLayerOwner  = MainSceneLayerOwner or {}
    ccb["MainSceneLayerOwner"] = MainSceneLayerOwner
    
    local function onCCControlButtonClicked()
        cclog("cc")
        
        if nil ~= MainSceneLayer["helloLabel"] then
            local ccLabelTTF = tolua.cast(MainSceneLayer["helloLabel"],"CCLabelTTF")
            if nil ~= ccLabelTTF then
                ccLabelTTF:setString("click button")
            end
        end
    end
    
            
    MainSceneLayer["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"] then
        cclog("aaaaaaaaaa");
        local ccLabelTTF = tolua.cast(MainSceneLayer["helloLabel"],"CCLabelTTF")
        if nil ~= ccLabelTTF then
            ccLabelTTF:setString("ccb/MainScene.ccbi")
        end
    end

    layer_root:addChild(layer);
    
    
    ---------------------------------------------------------
    -- 主场景
    local scene_main = CCScene:create();
    scene_main:addChild(layer_root);
    local curScene = CCDirector:sharedDirector():getRunningScene();
    if curScene ~= nil then
        CCDirector:sharedDirector():replaceScene(scene_main);
    else
        CCDirector:sharedDirector():runWithScene(scene_main);
    end
end

xpcall(main_test, __G__TRACKBACK__)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值