Question

I need to have my game transition from one scene to another in the storyboard api when the button pbtn is pressed. Here is my code.

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

I just needed to add this to the screenGroup for the transition to take place.

Was it helpful?

Solution 2

I just added all of my images to my group called screenGroup and everything worked fine!!!

OTHER TIPS

Do you have a 'game.lua' file in the same folder as this file ? When you call gotoscene('blabla') it will look for 'blabla.lua' in the current directory :)

I copied / pasted your code to test it here and it worked for me (with a game.lua file).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top