我正在尝试使用故事板切换场景,但是当我按下按钮时,它会保留当前场景……我无法在互联网上的任何地方找到解决此问题的方法.终端表示正在进入打印出“离开主菜单”的方法,并且我
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我找到了解决方案!如果我将背景图像和按钮添加到新的显示组,然后在场景退出时将其删除,则可以解决:
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