2

I'm making an app that will show animations of chemical reactions. Each atom is an SCNSphere and is animated with SCNActions. I'm trying to use the completion handler in runAction() to call the next animation after the current action is finished since there will be a lot of different movements each atom has to make.

This is just some test code I wrote to simplify the process, the actual code will be looping through an array of atom objects.

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")
    }
}

The print("Done") statement works just fine, it's only called once the action has finished, but the new SCNAction doesn't trigger. Am I missing something to make the next action start?

Gabe R
  • 82
  • 8

1 Answers1

0

I ended up going with

Timer.scheduledTimer(timeInterval: stepDuration, target: self,
                     selector: #selector(self.animate), userInfo: nil, repeats: true)

similar to James P's comment.

Gabe R
  • 82
  • 8