buttonluacoronasdkscenecorona-storyboard

Corona sdk composer wont got back to previous scene


I have used coronaSDK composer to have scenes in my application. i have a options button that is able to get to the options scene. however when i put a button on the option scene to go back to mainMenu scene it doesnt work

mainMenu.lua

local composer = require( "composer" )
local scene = composer.newScene()

-- "scene:create()"
function scene:create( event )

    local sceneGroup = self.view

    local backgroundimg = display.newImage("image/mainBackground.png")
    backgroundimg.x = display.contentWidth*0.5
    backgroundimg.y = display.contentHeight*0.5
    sceneGroup:insert( backgroundimg )

    local function startListener( event )
        composer.gotoScene( "scene.play" )
    end

    local start = display.newRect(65,99.5,161,161)
    start.alpha = 0.01
    start:addEventListener( "tap", startListener )

    local function leaderListener( event )
        composer.gotoScene( "scene.leaderboards" )
    end

    local leader = display.newRect(208,227.5,147,147)
    leader.alpha = 0.01
    leader:addEventListener( "tap", leaderListener )

    local function optionsListener( event )
        composer.gotoScene( "scene.options" )
    end

    local options = display.newRect(332,92.5,147,147)
    options.alpha = 0.01
    options:addEventListener( "tap", optionsListener )

    local function quitListener( event )
       os.exit()
    end

    local quit = display.newRect(432,240.5,120,120)
    quit.alpha = 0.01
    quit:addEventListener( "tap", quitListener )

end

-- "scene:show()"
function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then

    elseif ( phase == "did" ) then

    end
end

-- "scene:hide()"
function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then

    elseif ( phase == "did" ) then

    end
end

-- "scene:destroy()"
function scene:destroy( event )

    local sceneGroup = self.view

end

scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

return scene

options.lua

local composer = require( "composer" )

local scene = composer.newScene()

-- "scene:create()"
function scene:create( event )

    local sceneGroup = self.view

    local function startListener( event )
        composer.gotoScene( "scene.mainMenu" )
    end

    local start = display.newRect(65,99.5,161,161)
    start.alpha = 1
    start:addEventListener( "tap", startListener )
end

Solution

  • Try using:

    composer.gotoScene( "mainMenu" )
    

    Also, you are not adding the objects to the scene group. So, when the scene changes, the objects will not be removed automatically.