如何在timer.performWithDelay()之后运行一段代码?- Corona SDK

在这个脚本中:

function moveB()
    if B then
        B.x = B.x + 4
    end
end
function clickA()
    A.isVisible = false
    B.isVisible = true
    if fastSquare then
        B.x,B.y = A.x,A.y
        timer.performWithDelay(20,moveB,5)
        A.isVisible = true
        B.isVisible = false
    end
end
A:addEventListener("tap",clickA)

我想让这段代码运行:

A.isVisible = true
B.isVisible = false

timer.performWithDelay()调用函数moveB() 5次后运行,但即使我在timer.performWithDelay()下面放置了A.isVisible = false B.isVisible = true,它们也会同时运行。

点赞
用户2858170
用户2858170

将下面翻译成中文并且保留原本的 markdown 格式,

timer.performWithDelay(20, moveB, 5)

这句话的意思是:在 20 毫秒后调用 moveB 函数,总共执行 5 次。

由于此语句只是注册 moveB 的定时调用,因此任何在该语句之后的代码都将立即执行。

由于您已经在 if 语句之前设置了这些属性,因此无需在 if 语句内再次设置它们。这是没有效果的。

A.isVisible = false
B.isVisible = true
if fastSquare then
    B.x, B.y = A.x, A.y
    timer.performWithDelay(20, moveB, 5)
    A.isVisible = false -- 废弃
    B.isVisible = true -- 废弃
end
2020-08-07 07:30:33