MainScene.lua文件
local MainScene = class("MainScene", function()
return display.newScene("MainScene")
end)
function MainScene:ctor()
self:test2()
end
function MainScene:onEnter()
end
function MainScene:onExit()
end
function MainScene:test2()
-- body
--创建初始界面
local layer = cc.LayerColor:create(cc.c3b(255,0,0))
layer:setContentSize(display.width,display.height)
self:addChild(layer)
--创建文本
cc.ui.UILabel.new({
UILabelType = 2,
text = "干巴爹",
color = cc.c4b(255,255,0,255),
font = "Arial",
size = 64
})
:align(display.CENTER,display.cx,display.cy)
:addTo(layer)
--创建点击跳转按钮
cc.ui.UIPushButton.new({normal = "button/Button01.png",pressed = "button/Button01Pressed.png",})
:setButtonLabel("normal",cc.ui.UILabel.new({
UILabelType = 2,
color = display.COLOR_WHITE,
size = 48,
text = "页面跳转"
}))
:setButtonLabel("pressed",cc.ui.UILabel.new({
text = "页面跳转",
size = 48,
color = cc.c3b(220,240,40,255),
UILabelType = 2
}))
:onButtonClicked(function ( event )
-- body
local secondScene = import("app.scenes.SecondScene"):new()
display.replaceScene(secondScene,"fade",0.5,cc.c3b(255,0,0))
end)
:setPosition(display.width*0.2,display.height *0.5)
:addTo(layer)
end
return MainScene
SecondScene.lua文件
local SecondScene = class("SecondScene",function ()
-- body
return display.newScene("SecondScene")
end)
function SecondScene:ctor()
-- body
local label = cc.ui.UILabel.new({
UILabelType = 2,
text = "Second Scene",
size = 64,
color = cc.c3b(39,89,8),
align = cc.TEXT_ALIGNMENT_CENTER
})
label:setAnchorPoint(0.5,0.5)
label:setPosition(display.width*0.5,display.height*0.5)
self:addChild(label)
end
function SecondScene:onEnter()
-- body
end
function SecondScene:onExit()
-- body
end
return SecondScene
近期评论