Corona storyboard keeping the previous scene open

I try to switch scenes into a storyboard, but when I click the button, it saves the current scene ... I could not find a solution to this problem anywhere on the Internet. The terminal indicates that it gets to a method that displays "exit the main menu", and my next scene opens successfully, 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 
+4
source share
2 answers

I have found a solution! If I add both a background image and a button to a new display group, and then delete them when I exit the scene, this will work:

 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 
+1
source

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

It can help you.

0
source

Source: https://habr.com/ru/post/1440209/


All Articles