使用定时器管理警报的 Lua。
2015-3-5 18:57:13
收藏:0
阅读:97
评论:1
我在 LUA 中还比较新。当需要时,我使用计时器来弹出由 displaygroup 组成的警报。为了移除它们,我使用 timeperformwithdelay 函数调用一个 remove 函数,该函数会将 Self 引用的 displaygroup 对象移除。但是,我还有一个使用计时器函数的秒表。当秒表归零时,我弹出警报,然后在两秒钟后想要将其移除。但是,在这种情况下,remove 函数不起作用。以下是代码:
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
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
我修改了你的代码来进行测试。到目前为止,我制作的这个代码与你想要的要求配合良好。在lua中,要使函数有效,该函数必须位于该函数的顶部,这意味着如果您想从函数B调用函数A,函数A必须在函数B的顶部。
例如:
local functionA () end local functionB () functionA() end这里是我制作的代码片段,可以使您的代码按照您的意愿工作:
local alertDisplayGroup = display.newGroup() local timeLimit = 5 local function removeAlert() alertDisplayGroup:removeSelf() end local function timerDown() timeLimit = timeLimit-1 print(timeLimit) -- if timeLimit < 10 then -- print(timeLimit) -- else -- print(timeLimit) -- end if(timeLimit==0)then --timeLeft.text="0:00" alertScreen("Game 1","Time is over!") timer.performWithDelay(2000,removeAlert,1) timeLimit=5 end end function alertScreen(title, message) alertBox=display.newImageRect("images/error_message.png", 252, 85) alertBox.x=screenW/2 alertBox.y=screenH/2 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 timer.performWithDelay( 1000, function() timerDown() end, 0)正如您所看到的。我稍微编辑了它以进行测试。干杯。