将“删除警报屏幕作为显示组”翻译为英文为“Removing Alert screen as display group”。

我又在显示和移除Alert方面遇到了困惑。我使用Displaynew组创建了一个Alert屏幕。我有两个Alert,一个带有按钮(ALert1)以选择操作,而另一个没有按钮(Alert2)以确认操作。问题是,当我调用Alert1并选择使Alert2出现的操作时,我无法同时移除两个Alert。我调用Removealert函数来使两个Alert消失,但我只能删除Alert1。Alert2仍然存在。请帮帮我,谢谢。

以下是代码:

点赞
用户2653067
用户2653067

代码本身就有误,你在函数中声明了按钮,但是onRelease函数被声明为local,而且它们的位置在按钮下面。

首先,你应该知道lua是自上而下的方法,所以将代码改为以下方式并尝试:

``` local function removescore(event) scoreDisplayGroup:removeSelf() alertDisplayGroup:removeSelf() end

local function removeAlertScreenScore(event) scoreDisplayGroup:removeSelf()

end

local decidiOK = function(event)

if event.phase=="began" then score.add(punti) score.save() end alertScreen("","分数已保存!") --Alert2

timer.performWithDelay(1000,removescore,1) timeLimit=60 timeLeft.text = "1:00"

end

local decidiCancel = function( event )

if event.phase == "ended" then timer.performWithDelay(100,removeAlertScreenScore,1) end timeLimit=60 timeLeft.text = "1:00" end

function alertScreenScore(title, message) -- Alert1. Alert2 is similar with no buttons and is called alertScreenscore

alertBox=display.newImage("cornice.png") alertBox.x=W alertBox.y=H/1.3

transition.from(alertBox, {time=10,xScale=0.5,yScale=0.6,transition=easing.cutExpo})

titolomessaggio=display.newText(title,0,0,"Arial",100) titolomessaggio:setTextColor(255,255,0,255)

titolomessaggio.xScale=0.5 titolomessaggio.yScale=0.5 titolomessaggio.x=display.contentCenterX titolomessaggio.y=display.contentCenterY-100

testomessaggio=display.newText(message,0,0,"Arial",100) testomessaggio:setTextColor(255,255,0,255) testomessaggio.xScale=0.5 testomessaggio.yScale=0.5 testomessaggio.x=display.contentCenterX testomessaggio.y=display.contentCenterY+10

buttonCancel = widget.newButton { id = "buttonCancel", defaultFile = "buttonbn.png", label = "NO", labelColor = { default = { 0, 0, 0, 255 }, }, font = native.systemFont, fontSize = 30, emboss = true, onEvent = decidiCancel, isEnabled=true }

buttonOK = widget.newButton { id = "buttonOK", defaultFile = "buttonbn.png", label = "YES", labelColor = { default = { 0, 0, 0, 255 }, }, font = native.systemFont, fontSize = 30, emboss = true, onEvent = decidiOK, isEnabled=true } buttonCancel.x=250 buttonCancel.y=620

buttonOK.x=520 buttonOK.y=620

scoreDisplayGroup=display.newGroup() scoreDisplayGroup:insert(alertBox) scoreDisplayGroup:insert(titolomessaggio) scoreDisplayGroup:insert(testomessaggio) scoreDisplayGroup:insert(buttonCancel) scoreDisplayGroup:insert(buttonOK)

end

现在这应该可以工作了,将所有变量声明移到删除分数函数之前。

2015-03-20 05:19:11