【发布时间】:2015-03-06 11:19:04
【问题描述】:
我是 LUA 的新手。必要时,我正在使用计时器弹出警报,由显示组组成。为了删除它们,我使用了 timeperformwithdelay 函数,该函数调用了一个删除函数,该函数删除了引用 Self 的显示组对象。 但是,我也有一个秒表可以使用计时器功能。当秒表为零时,我会弹出警报,2 秒后我想将其删除。但在这种情况下,删除功能不起作用。以下是代码:
if timerleft==0 then
screenalert("Game 1","Time is over")
performwithdelay(2000,remove,1)
end
谢谢 您好,再次感谢您的支持。这是我的代码:
local function timerDown()
timeLimit = timeLimit-1
if timeLimit < 10 then
timeLeft.text = "0:0"..timeLimit
else
timeLeft.text = "0:"..timeLimit
end
if(timeLimit==0)then
timeLeft.text="0:00"
alertScreen("Game 1","Time is over!")
timer.performWithDelay(2000,removeAlert,1)
timeLimit=60
end
end
local function removeAlert()
alertDisplayGroup:removeSelf()
end
function alertScreen(title, message)
alertBox=display.newImage("cornice.png")
alertBox.x=W
alertBox.y=H/1.3
titolomessaggio=display.newText(title,0,0,"Arial",200)
titolomessaggio:setTextColor(255,255,0,255)
titolomessaggio.xScale=0.5
titolomessaggio.yScale=0.5
titolomessaggio.x=display.contentCenterX
titolomessaggio.y=display.contentCenterY-200
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
alertDisplayGroup=display.newGroup()
alertDisplayGroup:insert(alertBox)
alertDisplayGroup:insert(titolomessaggio)
alertDisplayGroup:insert(testomessaggio)
end
【问题讨论】:
-
你的
remove函数是做什么的?它期望操作什么,因为我无法想象当以这种方式调用它时它会获得任何上下文或参数。 -
嗨,Etan,感谢您的回答。其实这个功能没有任何作用!我想它应该删除我用来创建 screenAlert 的显示组(一个图像和两个文本行)。但是,例如,当我在游戏开始时调用它时,当我显示带有游戏级别编号的警报时,相同的函数会起作用。我错过了什么吗?
-
remove函数是什么样的?需要争论吗?它是某个对象/表的“成员”函数吗? -
Etan,这是我的代码:本地函数 timerDown() timeLimit = timeLimit-1 if timeLimit
-
这是要删除的函数:local function removeAlert() alertDisplayGroup:removeSelf() end