当按下按钮 pbtn 时,我需要在情节提要 api 中让我的游戏从一个场景过渡到另一个场景。这是我的代码。
local storyboard = require "storyboard"
local scene = storyboard.newScene()
--Forward References
local title
local centerX = display.contentCenterX
local centerY = display.contentCenterY
display.setStatusBar(display.HiddenStatusBar)
function anim_pbtn(event)
transition.to(pbtn, {time = 500, alpha = 0, xScale = 2, yScale = .6})
storyboard.gotoScene("game", "fade", 1000)
end
function scene:createScene(event)
local screenGroup = self.view
mbg = display.newImage("mbg.png")
mbg.x = centerX
mbg.y = centerY
mbg.width = display.width
mbg.height = display.height
title = display.newImage("title.png")
title.xScale = .7
title.yScale = .7
title.x = centerX
pbtn = display.newImage("play_btn.png")
pbtn.xScale = .7
pbtn.yScale = .7
pbtn.x = centerX
pbtn.y = display.contentHeight - 210
ibtn = display.newImage("ins_btn.png")
ibtn.xScale = .7
ibtn.yScale = .7
ibtn.x = centerX
ibtn.y = display.contentHeight - 130
cbtn = display.newImage("cre_btn.png")
cbtn.xScale = .7
cbtn.yScale = .7
cbtn.x = centerX
cbtn.y = display.contentHeight - 50
end
function scene:enterScene(event)
pbtn:addEventListener("tap", anim_pbtn)
end
function scene:exitScene(event)
end
function scene:destroyScene(event)
end
scene:addEventListener("createScene", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
scene:addEventListener("destroyScene", scene)
return scene
我只需要将它添加到 screenGroup 即可进行转换。