I have two SKSpriteKitNodes
, one in the left and one in the right. Then I detect where is the location of the touch and make the action according to its location (the left side shoots, and the right side speeds up). But the thing is, if the left is being touched, how can I handle the right-side touch at the same time?
The code I have so far:
let left = SKSpriteNode()
let right = SKSpriteNode()
override func didMoveToView(view: SKView) {
left.size = CGSize(width: frame.width / 2, height: frame.height)
right.size = CGSize(width: frame.width / 2, height: frame.height)
left.position = CGPoint(x: frame.width / 4, y: frame.height / 2)
right.position = CGPoint(x: 3 * frame.width / 4, y: frame.height / 2)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches{
let location = touch.locationInNode(self)
if right.containsPoint(location){
//HANDLE THE SPEED
if speed == 0{
speed = 5
}
shouldBreak = false
}
if left.containsPoint(location){
//HANDLE THE SHOOTING
shoot.position = CGPoint(x: frame.midX, y: frame.height * 0.2)
isShooting = true
}
}