-1

当按下按钮 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 即可进行转换。

4

2 回答 2

0

我刚刚将我所有的图像添加到我的名为 screenGroup 的组中,一切正常!!!

于 2013-11-01T22:50:15.977 回答
0

您在与此文件相同的文件夹中是否有“game.lua”文件?当您调用 gotoscene('blabla') 时,它将在当前目录中查找 'blabla.lua' :)

我复制/粘贴了您的代码以在此处对其进行测试,它对我有用(使用 game.lua 文件)。

于 2013-10-31T00:11:32.223 回答