Moving multiple nodes at the same time is quite simple. The key is to track each touch event independently. One way to do this is to maintain a dictionary that uses a touch event when a key and node move as a value.
Declare a dictionary first
var selectedNodes:[UITouch:SKSpriteNode] = [:]
Add each dictionary sprite using a touch event as a key
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = touch.location(in:self) if let node = self.atPoint(location) as? SKSpriteNode { // Assumes sprites are named "sprite" if (node.name == "sprite") { selectedNodes[touch] = node } } } }
Update sprite position as needed
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { let location = touch.location(in:self) // Update the position of the sprites if let node = selectedNodes[touch] { node.position = location } } }
Extract sprite from dictionary when touch ends
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { if selectedNodes[touch] != nil { selectedNodes[touch] = nil } } }
source share