Lua 如何将小部件的可见性设置为false?
所以,我有这个函数:Lua 如何将小部件的可见性设置为false?,lua,coronasdk,Lua,Coronasdk,所以,我有这个函数: local function addMainMenu() local widget = require( "widget" ) -- Function to handle button events local function handleButtonEvent( event ) if ( "ended" == event.phase ) then scene = "GAME" end
local function addMainMenu()
local widget = require( "widget" )
-- Function to handle button events
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
scene = "GAME"
end
end
-- Create the widget
local button1 = widget.newButton(
{
label = "button",
onEvent = handleButtonEvent,
emboss = false,
-- Properties for a rounded rectangle button
shape = "roundedRect",
width = 200,
height = 40,
cornerRadius = 2,
fillColor = { default={0.9,0.9,0.9,1}, over={1,0.1,0.7,0.4} },
strokeColor = { default={0,0,0,1}, over={0.8,0.8,1,1} },
strokeWidth = 5
}
)
-- Center the button
button1.x = display.contentCenterX
button1.y = display.contentCenterY
-- Change the button's label text
button1:setLabel( "Start Game" )
end
这增加了启动游戏的按钮,然后我有:
local function enterFrame()
local dt = getDeltaTime()
if (scene == "MAIN_MENU") then
addMainMenu()
elseif (scene == "GAME") then
if (running == false) then
startGame()
else
moveBg(dt)
moveEnemy(enemy)
updateScore()
end
elseif (scene == "GAME_OVER") then
local gameOverLabel = display.newText( "Game Over!", 50, 20, native.systemFont, 16)
gameOverLabel:setFillColor(1, 1, 1)
end
end
正如你所看到的,一旦我点击按钮开始,场景就会变为“游戏”,按钮就会消失。问题是:它就在那里,我找不到将其可见性设置为false的方法。如何停止显示小部件?a inherits from,提供属性
概述
控制对象在屏幕上是否可见。这个
属性也是可读的。默认值为true
示例
local rect1=display.newRect(100,100,50,50)
rect1:setFillColor(0.7)
local rect2=display.newRect(150,100,50,50)
rect2:setFillColor(1,0,0,0.6)
rect2.isVisible=false
button1.isVisible=false
将隐藏按钮。它将随着下一次屏幕更新而消失
如果您不再需要该按钮,您也可以通过调用
按钮1:removeSelf()
将其删除,或者通过将其从其父组中删除以使其不可见。isVisible:
button1.isVisible = false
要隐藏它,请使用.alpha
button1.alpha = 0.00
-- or hide just a little by 50%
button1.alpha = 0.50
要删除它,请执行以下操作:
display.remove( button1)
button1= nil
答案在手册中,或者只需将“隐藏按钮电晕”输入谷歌搜索引擎即可找到