lua – Corona故事板保持以前的场景开放

我正在尝试使用故事板切换场景,但是当我按下按钮时,它会保留当前场景……我无法在互联网上的任何地方找到解决此问题的方法.终端表示正在进入打印出“离开主菜单”的方法,并且我的下一个场景成功打开,但背景和按钮保留在原始场景中.

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); 

    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

解决方法

我找到了解决方案!如果我将背景图像和按钮添加到新的显示组,然后在场景退出时将其删除,则可以解决

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

    print("menu scene viewing!")

    local bgImage = display.newImage("images/mainBG.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.github代码实践源代码是lua脚本语言,下载th之后运行thmai...
此文为搬运帖,原帖地址https://www.cnblogs.com/zwywilliam/...
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能...
localfunctiongenerate_action(params)localscale_action=cc...
2022年1月11日13:57:45 官方:https://opm.openresty.org/官...
在Lua中的table(表),就像c#中的HashMap(哈希表),key和...