4

我正在尝试使用情节提要切换场景,但是当我按下按钮时,它会保留当前场景......我无法在互联网上的任何地方找到解决此问题的方法。终端提示正在进入打印“离开主菜单”的方法,我的下一个场景成功打开了,但是背景和按钮还是原来的场景。

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

2 回答 2

1

我找到了解决办法!如果我将背景图像和按钮都添加到一个新的显示组中,然后在场景退出时将它们删除,则可以解决:

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
于 2012-10-17T18:28:20.713 回答
0

请参考以下链接 - http://docs.coronalabs.com/api/library/storyboard/removeScene.html

这可以帮助你。

于 2013-04-16T07:53:34.907 回答