首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在corona中停止监听'x‘秒

在corona中停止监听'x‘秒
EN

Stack Overflow用户
提问于 2012-09-25 01:18:26
回答 1查看 375关注 0票数 0

我有一个基于摇动事件的淡入/淡出函数,但如果你在函数中再次摇动它,它会堆叠这些函数。我希望它等到函数结束(5秒),然后再次侦听。它的代码是什么?

这是我目前所拥有的:

代码语言:javascript
复制
function fadeOut ( event )
    transition.to(yes1, {time=2000, alpha=0})
    transition.to(yes2, {time=2000, alpha=0})
    ...
    transition.to(funny3, {time=2000, alpha=0})
    transition.to(funny4, {time=2000, alpha=0})
    timer.performWithDelay(2000, onShakeComplete)
end

responses = {yes1, yes2, yes3, yes4, yes5, yes6, yes7, yes8, yes9, yes10,
no1, no2, no3, no4, no5, maybe1, maybe2, maybe3, maybe4, maybe5,
funny1, funny2, funny3, funny4}

local shaking = false

-- reset shaking flag after a shake is completed
local function onShakeComplete()
    shaking = false
end

local function onShake (event)
        if event.isShake and not shaking then
        shaking = true
        local object = responses[math.random(1,20)]
        transition.to(object, {time=2000, alpha=1})
        timer.performWithDelay(4000, fadeOut)
    end
end
Runtime:addEventListener("accelerometer", onShake)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-25 01:34:30

代码语言:javascript
复制
-- true if we have a shake happening right now
local shaking = false

-- reset shaking flag after a shake is completed
local function onShakeComplete()
    shaking = false
end

local function onShake (event)
    if event.isShake and not shaking then
        local object = responses[math.random(1,20)]
        transition.to(object, {time=2000, alpha=1})
        timer.performWithDelay(4000, fadeOut)
        timer.performWithDelay(4000, onShakeComplete)
        shaking = true
    end
end
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12569803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档