Reputation: 73
I know how to create a sequence of SCNActions in a single node, one by one, in SceneKit. But I would like to know, how can I make a sequence of SCNActions with different nodes? For example
I found an example with SpriteKit but I can not use it, this... Run SKActions sequence with different nodes
The code of a sequence is as follows
var sequence = [SCNAction] ()
let force = SCNVector3(0.0, 0.0, -1.0)
let move = SCNAction.move(by: force!, duration: 1.5)
squence.append(move)
let actions = SCNAction.sequence(squence)
nodeSelected?.runAction(actions)
Upvotes: 3
Views: 1520
Reputation: 1611
you can use customAction
.
let actionA = SCNAction.customAction(duration: 1.5) { (node, elapsedTime) in
nodeA.position.z -= 1.0
}
let actionB = SCNAction.customAction(duration: 1.5) { (node, elapsedTime) in
nodeB.position.z -= 1.0
}
let sequence = SCNAction.sequence([actionA,actionB])
anyNode.runAction(sequence)
Running action with any node will first move nodeA then nodeB.
Upvotes: 5