在cococs2d LUA 顯示cococs (cococs Studio)讀取 csb 檔案

LUA 讀取 csb 檔案

local MainScene = class("MainScene", cc.load("mvc").ViewBase)

function MainScene:onCreate()
    -- add background image
   -- display.newSprite("MainSceneBg.jpg")
   --     :move(display.center)
   --     :addTo(self)

    -- add play button
    local playButton = cc.MenuItemImage:create("PlayButton.png", "PlayButton.png")
        :onClicked(function()
            self:getApp():enterScene("PlayScene")
        end)
    cc.Menu:create(playButton)
        :move(display.cx, display.cy - 200)
        :addTo(self)
        
    -----------------------------


    local function RunExportedCSB(csbFileName)
        -- get root node from csb file.
        local node = cc.CSLoader:createNode(csbFileName)
       
        -- run animation in the scene
        local action = cc.CSLoader:createTimeline(csbFileName)
        node:runAction(action)
        action:gotoFrameAndPlay(0, true)

        -- add csb returned node to scene.
        local runningScene = cc.Director:getInstance():getRunningScene()
        if runningScene then
           -- runningScene:addChild(node)
           -- runningScene:addChild(node)
            self:addChild(node)
        end
    end

    RunExportedCSB("MainScene.csb")
        
        
end

Screen Shot 2015-06-28 at 10.06.00 AM

cococs2d-x LUA
CH02 LUACH04 SceneCH05 SpriteCH09 Cocos2d 原始程式CH10 cocos (cocos studio)CH11 工具CH99範例