gpt4 book ai didi

lua - 电晕 Storyboard保持之前的场景打开

转载 作者:行者123 更新时间:2023-12-04 16:06:59 27 4
gpt4 key购买 nike

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

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

关于lua - 电晕 Storyboard保持之前的场景打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12927988/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com