如何一个接一个地进行一些过渡

时间:2015-10-25 08:42:49

标签: function lua corona

我目前正在尝试一个接一个地进行一些转换,但我可以找到一种方法让许多人一个接一个地在同一个函数中工作。我现在的方式(下面)有效,但我讨厌它是如此混乱。

function screenLowering()
  local start = transition.to(backdrop,{time = 1000, x = centerX, y = height/2, onComplete = screenBounce})
end

function screenBounce()
  local bounce = transition.to(backdrop,{time = 250, x = centerX, y = backdrop.y - 50, onComplete = screenBounce2})
end

function screenBounce2()
  local bounce = transition.to(backdrop,{time = 300, x = centerX, y = backdrop.y + 50})
end

1 个答案:

答案 0 :(得分:0)

function chain_of_transitions(object, params, ...)
   if params then
      if params.dx then
         params.x, params.dx = object.x + params.dx
      end
      if params.dy then
         params.y, params.dy = object.y + params.dy
      end
      function params.onComplete() 
         chain_of_transitions(object, ...) 
      end
      transition.to(backdrop, params)
   end
end

chain_of_transitions(backdrop,
   {time = 1000, x = centerX, y  = height/2},
   {time = 250,  x = centerX, dy = -50},
   {time = 300,  x = centerX, dy = 50}
)