如何将SkAction放到另一个的末尾?

时间:2017-01-21 17:48:11

标签: swift sprite-kit

所以例如我有一个块向左侧移动2秒但是在你看到他在两秒钟后停止之前有一个0.2秒长的fadeOut动画并且会在该块移动1.8秒后开始运行,我尝试用组或序列以某种方式管理它,但它不起作用,所以我该怎么做?

1 个答案:

答案 0 :(得分:2)

使用SKAction.sequenceSKAction.group的组合创建两个并行运行的操作。其中一个动作将是一个结合等待和淡入淡出的序列:

let pause = SKAction.wait(forDuration: 1.8)
let fade = SKAction.fadeAlpha(to: 0, duration: 0.2)
let move = SKAction.moveTo(x: 0, duration: 2)

// sequence creates an action that runs a collection
// of actions sequentially (one after the other)
// pause 1.8 seconds, and then fade for 0.2 seconds
let pauseAndFade = SKAction.sequence([pause, fade])

// group creates an action that runs a collection of
// actions in parallel (at the same time)
// run move and pauseAndFade in parallel
let moveAndFade = SKAction.group([move, pauseAndFade])

moveAndFade动作将按照你想要的方式行动:将动作块向左移动2秒,然后在动作的最后0.2秒内淡出。