1
votes

I've got this problem that is delaying my game by a milestone, in scene1 I click the menu button that takes me to the menu then when the user wants to play again they click the play button and they should go to the previous scene however when it does its goes to a black screen. here is some code, this is the main menu button in scene 1:

function scene:enterScene(event)

 local group = self.view

 function menubutton:touch( event )
if event.phase == "began" then
    storyboard.gotoScene( "menu", "slideRight", 750 )
    audio.play(click)
    display.getCurrentStage():setFocus( event.target )
    event.target.isFocus = true
elseif event.target.isFocus then
    if event.phase == "moved" then
        print( "user has moved their finger off the button." )
    elseif event.phase == "ended" then
        print( "user has switched to the main menu" )
        display.getCurrentStage():setFocus( nil )
        event.target.isFocus = false
    end
end
return true

end

here is the play button on the main menu:

function scene:enterScene(event)
local group = self.view 

local function onSceneTouch( event )
    if event.phase == "ended" then
       audio.play(click)
       local previousScene = storyboard.getPrevious()
       if previousScene == nil then
       storyboard.gotoScene( "scene1", "slideLeft", 750 ) else
       storyboard.gotoScene(previousScene)
        return true
    end
 end
end

any ideas? I am getting NO errors in the simulator output.

Edit: This line of code stopped the blank screen when i placed it on the menu, but only the images show up, background image button images etc but nothing else.

local prior_scene = storyboard.getPrevious()
storyboard.purgeScene( prior_scene )
1
Does anyone have an ideas? I cannot find anyone else with the same problem. - Zac Baker
It's going to be really hard to figure out why you're getting a blank scene without seeing your scene creation code. Though I am also curious as to why you are calling previousScene? Don't you now what scene you need to go to from your menu? Have you printed out the value of previousScene to make sure it's what you're expecting? - Rob Miracle
I am calling previous scene because i want it to take the user to the last scene where they left off. Its a word find game, I'm trying to do the concept of 4 pics 1 word with how you can go to the menu and then when you feel like playing again you just tap play and it takes you to the last level you were on. - Zac Baker
Check the edit i made down the bottom on my first post. - Zac Baker
well the full code is in a thread on corona labs that no one has ended up replying to for a while: forums.coronalabs.com/topic/… - Zac Baker

1 Answers

0
votes

Try to use a tap listener instead of touch listener. I don't see your entire code but I think there is the problem.

main menu button in scene 1:

function scene:enterScene(event)

    local group = self.view

    local function onMenuButtonTap( event )
        audio.play(click)
        storyboard.gotoScene( "menu", "slideRight", 750 )
        return true
    end
end

play button on the main menu scene:

function scene:enterScene(event)
    local group = self.view 

    local function onPlayTap( event )
        audio.play(click)
        local previousScene = storyboard.getPrevious()
        if previousScene == nil then
            storyboard.gotoScene( "scene1", "slideLeft", 750 )
        else
            storyboard.gotoScene(previousScene)
        end
        return true
    end
end

------------------------------------------------------------
New code:
------------------------------------------------------------

change this in your scene1.lua

function scene:exitScene(event)

    local group = self.view
    storyboard.destroyScene( "scene1" )

end

with this

function scene:exitScene(event)

     local group = self.view

end

In your menu.lua add this:

function scene:createScene( event )
    local group = self.view

    storyboard.purgeScene( "scene1" )
end

scene:addEventListener( "createScene", scene )