Here is more detailed code :). I also tried using run(_:completion:) and the same thing happens - the run does not wait for the action to complete before running the completion code.
let actionA = SKAction.run { [unowned self] in
var currNodes: [DanceNode] = []
self.enumerateChildNodes(withName: "draggable") { (node, stop) in
currNodes.append(node as! DanceNode)
}
self.formationVM.formationArray = self.formationVM.loadFormations()
if let nextFormation = self.formationVM.getNextFormation(){
let nextDancerForms = self.dancerVM.loadNextDancers(nextFormation: nextFormation)
for dancer in nextDancerForms{
if let toUpdateIndex = currNodes.firstIndex(where: { $0.nodeId == dancer.id }) {
let next = CGPoint(x: CGFloat(dancer.xPos), y: CGFloat(dancer.yPos))
let action = SKAction.move(to: next , duration: 1.0)
currNodes[toUpdateIndex].run(action)
}
}
self.formationVM.currentIndex += 1
}
}
let sequence = SKAction.sequence([actionA, actionA, actionA, actionA])
self.run(sequence)
}
Post
Replies
Boosts
Views
Activity
I figured it out! The problem was that I was not waiting before executing the next action.