FlatterLR
FlatterLR

Reputation: 73

Corona storyboard keeping previous scene open

I'm attempting to switch scenes with the storyboard, but when I press the button, it keeps the current scene... I haven't been able to find a solution to this issue anywhere on the internet. The terminal indicates that it is getting to the method that prints out "leaving main menu", and my next scene is successfully opened, but the background and button remain from the original scene.

local storyboard = require( "storyboard" )  
local widget = require "widget"  
local scene = storyboard.newScene()

local function onButton(event)
--local btn = event.target
--storyboard.gotoScene("sceneTemplate")
if event.phase == "release" then 
    print("play pressed")
    storyboard.gotoScene("sceneTemplate")
   end
end

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

    print("menu scene created")
end

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

    print("menu scene viewing!")

    local bgImage = display.newImage("images/mainBG.png",0,0); 

    local playButton = widget.newButton{
        default = "images/playUp.png", 
        over = "images/playDown.png",
        onEvent = onButton
    }
    playButton.x = 80
    playButton.y = 20
end

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

    print("leaving main menu")
    storyboard.removeScene("menu")
    storyboard.removeAll()
    display.remove(group)
    group:removeSelf()
  end

Upvotes: 4

Views: 1685

Answers (2)

Varsha
Varsha

Reputation: 558

Please refer the below link- http://docs.coronalabs.com/api/library/storyboard/removeScene.html

This can help you.

Upvotes: 0

FlatterLR
FlatterLR

Reputation: 73

I found a solution! If I add both the background image and the button to a new display group, and then remove them upon the scene exiting, it works out:

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

    print("menu scene viewing!")

    local bgImage = display.newImage("images/mainBG.png",0,0); 

    local playButton = widget.newButton{
        default = "images/playUp.png", 
        over = "images/playDown.png",
        onEvent = onButton
    }

    displayGroup:insert(bgImage)
    displayGroup:insert(playButton)
end

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

    print("leaving main menu")
    display.remove(displayGroup)
    storyboard.removeScene("menu")

end

Upvotes: 1

Related Questions