1

有没有办法防止角色同时开始?我试过这个,但即使我添加了延迟,每个角色仍然会在动画开始的那一刻开始动作。

--runningPG1.. runningPG5 have attached a sprite and coordinates
arrayPg = {runningPG1, runningPG2, runningPG3, runningPG4, runningPG5}

for key, value in pairs(arrayPg) do 
    transition.to(value, { y = value.y+350, time = 1500})
    transition.to(value, { x = value.x-740, time = 2500, delay = 1550 })
    transition.to(value, { y = value.y+825, time = 2500, delay = 4100 })
end
4

1 回答 1

1

如果您希望每个人在不同的时间开始,我认为您需要根据循环中的数字添加延迟。就像是:

--runningPG1.. runningPG5 have attached a sprite and coordinates
arrayPg = {runningPG1, runningPG2, runningPG3, runningPG4, runningPG5}

baseDelay = 0
for key, value in pairs(arrayPg) do 
    transition.to(value, { y = value.y+350, time = 1500, delay = baseDelay })
    transition.to(value, { x = value.x-740, time = 2500, delay = baseDelay + 1550 })
    transition.to(value, { y = value.y+825, time = 2500, delay = baseDelay + 4100 })
    baseDelay = baseDelay + 500
end

或者你也可以使用随机延迟

for key, value in pairs(arrayPg) do 
    baseDelay = math.random(0, 2000)
    transition.to(value, { y = value.y+350, time = 1500, delay = baseDelay })
    transition.to(value, { x = value.x-740, time = 2500, delay = baseDelay + 1550 })
    transition.to(value, { y = value.y+825, time = 2500, delay = baseDelay + 4100 })
end
于 2021-01-13T18:31:22.387 回答