运行 SceneKit 中不同节点的 SCNActions 序列
Run SCNActions sequence with different nodes in SceneKit
我知道如何在 SceneKit 中一个接一个地在单个节点中创建一系列 SCNActions。但我想知道,我怎样才能用不同的节点制作一系列 SCNActions?
例如
- 前移节点A
- 向前移动节点 B
- 等待 1 秒
- 向后移动节点 A
I found an example with SpriteKit but I can not use it, this...
Run SKActions sequence with different nodes
一个序列的代码如下
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)
您可以使用 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)
运行 对任何节点的操作将首先移动节点A,然后移动节点B。
我知道如何在 SceneKit 中一个接一个地在单个节点中创建一系列 SCNActions。但我想知道,我怎样才能用不同的节点制作一系列 SCNActions? 例如
- 前移节点A
- 向前移动节点 B
- 等待 1 秒
- 向后移动节点 A
I found an example with SpriteKit but I can not use it, this... Run SKActions sequence with different nodes
一个序列的代码如下
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)
您可以使用 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)
运行 对任何节点的操作将首先移动节点A,然后移动节点B。