1

I am making a simple Pong game using SpriteKit + Swift. It is a multiplayer game, so I want two people to be able to move the two paddles. I want to be able to move the paddles at the same time. When I run the code below, which is the touchesBegan function, I am only able to move each paddle when one finger is pressing the display. When I try to touch another paddle, while my finger is already on the screen, it does not respond.

 let touch = touches.first as UITouch?
 let touchLocation = touch?.locationInNode(self)
 let body: SKPhysicsBody? = self.physicsWorld.bodyAtPoint(touchLocation!)

 if body?.node!.name == PaddleCategoryName {
     print("Paddle Touched!")
     fingerIsOnPaddle = true
 } else if body?.node!.name == PaddleCategoryName2 {
     print("Paddle2 Touched!")
     fingerIsOnPaddle2 = true
 }
  • It's only a guess - but have you tried using more than one touch responder? maybe splitting your screen into two view controllers and each one with it's touch responder? – Nitzan R Oct 18 '15 at 06:00
  • I have tried using multiple touch responders, but I have not tried splitting the screen into two view controller. I am new to SpriteKit, so do you know how to do that? – Shawn Patel Oct 18 '15 at 06:04
  • I'm also not that experienced with SpriteKit. If I were you I would ask a new question about it. – Nitzan R Oct 18 '15 at 06:08
  • Alright thanks for the help! – Shawn Patel Oct 18 '15 at 06:09
  • Apple has a sample games that has two inputs, I also use two custom touch views over the scene as an alternative to a remote game controller. The Apple sample is DemoBots or something... – Duncan Groenewald Oct 18 '15 at 06:47
  • Have you tried this? http://stackoverflow.com/questions/27343926/multi-touch-gesture-in-sprite-kit – WangYudong Oct 18 '15 at 12:41
  • Adding my comment from the other newer question (saw that one first). I'm not sure that is really what you want to do. You might be better getting the location of the touch, so you can just use that location to see if it on one side of the iDevice or the other. Same would go for touchesMoved, just see where the location of the touch is, and move the paddle on that side. – Gliderman Oct 18 '15 at 13:39
  • I did try using the other question, but it did not seem to work for me. – Shawn Patel Oct 18 '15 at 17:13

1 Answers1

0

I know this is a bit late but if you still dont know the answer I believe you need to set this line in your viewController when loading your first scene

 skView.multipleTouchEnabled = true
crashoverride777
  • 10,581
  • 2
  • 32
  • 56