cococos 2 d-luaはcocostudioが作成した2つのcsbシーンを切り替えます

2068 ワード

最初のシーンはloginscene.csb、2番目のシーンはhomescneです.csb
最初のシーンコードは次のとおりです.
local MainScene = class("MainScene", cc.load("mvc").ViewBase)

function MainScene:onCreate()
    local uiRoot = cc.CSLoader:createNode("loginscene.csb")
    uiRoot:addTo(self)
    self:initEvent(uiRoot)
end

function MainScene:initEvent(uiRoot)
    local button = uiRoot:getChildByName("btn_login");
    if button then
        button:addTouchEventListener(function (event,type)
            if type == ccui.TouchEventType.began then
                print(" ")
            end

            if type == ccui.TouchEventType.ended then
                local scene = require("app/views/HomeScene.lua")
                local gameScene=scene:create()
                -- 
                if cc.Director:getInstance():getRunningScene() then
                    -- 
                    cc.Director:getInstance():replaceScene(gameScene)
                else
                    -- 
                    cc.Director:getInstance():runWithScene(gameScene)
                end
            end
        end)
    end
end

return MainScene

2番目のシーンコードは次のとおりです.
-- 
local HomeScene = class("HomeScene", function()
    return cc.Scene:create()
end)

-- 
function HomeScene:ctor()
    self.winsize=cc.Director:getInstance():getWinSize()
    local csbNode = cc.CSLoader:createNode("homescene.csb")
    csbNode:setAnchorPoint(0.5, 0.5)
    csbNode:setPosition(self.winsize.width/2, self.winsize.height/2)
    self:addChild(csbNode)
end

-- create 
function HomeScene:create()
    local scene = HomeScene.new()
    scene:addChild(scene:init())
    return scene
end

-- 
function HomeScene:init()
    local layer=cc.Layer:create()
    -- , Label 
    local label=cc.LabelTTF:create("PlaneGame"," ",45)
    label:setString("PlaneGame")
    label:setScale(3)
    label:setPosition(self.winsize.width/2,self.winsize.height-100)
    layer:addChild(label)
    return layer
end
return HomeScene