1

is it possible to have the touchesBegan method in multiple locations or objects in a project?

for example if I have a main class with two buttons:

class GameScene: SKScene, SKPhysicsContactDelegate {
 let moveButton = MoveButton()
 let fireButton = FireButton()
 //add buttons to scene etc...
}

class MoveButton: SKSpriteNode {
 override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
  NSLog("moved!")
 }
}

class FireButton: SKSpriteNode {
 override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
  NSLog("fired!")
 }
}

currently I have something similar but the touchesBegan aren't being hit, is this incorrect to do?

Abdul Ahmad
  • 9,673
  • 16
  • 64
  • 127

1 Answers1

1

Yes, it should be perfectly fine to implement touchesBegan in several places. Regarding why they aren't called, perhaps this can help? Custom SKSpriteNode not detected during touch

Community
  • 1
  • 1
Rick
  • 3,240
  • 2
  • 29
  • 53