ios - Asynchronous moving of 2 nodes sprite kit -
i have 2 nodes, want grab 2 fingers asynchronously on ipad. that's code moving:
var ninjamoving = false var monstermoving = false var loc = cgpoint(x: 0.0, y: 0.0) var prevloc = cgpoint(x: 0.0, y: 0.0) override func touchesbegan(touches: set<nsobject>, withevent event: uievent) { touch in (touches as! set<uitouch>) { let location = touch.locationinnode(self) if !self.nodesatpoint(location).isempty && (self.nodeatpoint(location).physicsbody?.categorybitmask == 1 || self.nodeatpoint(location).physicsbody?.categorybitmask == 3) { if self.nodeatpoint(location).physicsbody?.categorybitmask == 1 { ninjamoving = true } else if self.nodeatpoint(location).physicsbody?.categorybitmask == 3 { monstermoving = true } } } } override func touchesmoved(touches: set<nsobject>, withevent event: uievent) { touch in touches as! set<uitouch> { loc = touch.locationinnode(self) prevloc = touch.previouslocationinnode(self) } } override func touchesended(touches: set<nsobject>, withevent event: uievent) { touch in touches as! set<uitouch> { let location = touch.locationinnode(self) if self.nodeatpoint(prevloc).physicsbody?.categorybitmask == 1 { ninjamoving = false } if self.nodeatpoint(prevloc).physicsbody?.categorybitmask == 3 { monstermoving = false } } } override func update(currenttime: cftimeinterval) { if ninjamoving { var x = playerninja.position.x + (loc.x - prevloc.x) var y = playerninja.position.y + (loc.y - prevloc.y) x = max(x, playerninja.size.width / 2) x = min(x, size.width / 2 - playerninja.size.width) y = max(y, playerninja.size.height / 2) y = min(y, size.height - playerninja.size.height / 2) playerninja.position = cgpointmake(x, y) } if monstermoving { var x = playermonster.position.x + (loc.x - prevloc.x) var y = playermonster.position.y + (loc.y - prevloc.y) x = max(x, self.size.width / 2 + playermonster.size.width) x = min(x, size.width - playermonster.size.width / 2) y = max(y, playermonster.size.height / 2) y = min(y, size.height - playermonster.size.height / 2) playermonster.position = cgpointmake(x, y) } } but can't move 1 of sprites left, , right @ same time. there way in sprite kit?
please check answer question: multitouch in spritekit
the idea should track individual touches separately.
Comments
Post a Comment