【发布时间】:2015-03-20 13:19:11
【问题描述】:
我在那里,我再次为显示和删除警报而苦苦挣扎。我使用 Displaynew 组制作了一个警报屏幕。我有两个,一个带有按钮(ALert1)来选择动作,一个没有按钮(Alert2)来确认动作。问题是,当我调用 Alert1 并选择使 Alert2 出现的操作时,我无法同时删除这两个 Alert。我调用 Removealert 函数使两者都消失,但我只设法删除 Alert1。 Alert2 仍然存在。请帮忙,谢谢。
以下是代码:
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
local decidiOK = function(event)
if event.phase=="began" then
score.add(punti)
score.save()
end
alertScreen("","Score saved!") --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
local function removescore(event)
scoreDisplayGroup:removeSelf()
alertDisplayGroup:removeSelf()
end
local function removeAlertScreenScore(event)
scoreDisplayGroup:removeSelf()
end
【问题讨论】: