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

    LUA 讀取 csb 檔案

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    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