我正在制作一个将显示化学反应动画的应用程序。每个原子都是一个SCNSphere,并使用SCNActions进行动画处理。我正在尝试使用runAction()中的完成处理程序在当前操作完成后调用下一个动画,因为每个原子必须进行很多不同的动作。
这只是我为简化过程而编写的一些测试代码,实际代码将遍历atom
对象的数组。
func animate() {
let atom1 = atomNodes[0]
atom1.runAction(atoms[0].actions[0]) {
atom1.runAction(SCNAction.move(by: SCNVector3(-10, 0, 0), duration: 1.0))
print("Done")
}
}
print("Done")
语句工作得很好,只有在操作完成后才调用它,但是新的SCNAction不会触发。我是否缺少一些使下一个动作开始的东西?
答案 0 :(得分:0)
我最终选择了
Timer.scheduledTimer(timeInterval: stepDuration, target: self,
selector: #selector(self.animate), userInfo: nil, repeats: true)
类似于James P的评论。