在SpriteKit + Swift中同时移动两个拨片

时间:2015-10-18 04:47:31

标签: ios swift sprite-kit touchesbegan

我正在使用SpriteKit + Swift制作简单的Pong游戏。这是一个多人游戏,所以我希望两个人能够移动两个桨。我希望能够同时移动拨片。当我运行下面的代码,即touchesBegan功能时,我只能在一根手指按下显示器时移动每个拨片。当我尝试触摸另一个拨片时,当我的手指已经在屏幕上时,它没有响应。

 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
 }

1 个答案:

答案 0 :(得分:0)

我知道这有点晚了但是如果你还不知道答案我相信你需要在加载你的第一个场景时在你的viewController中设置这一行

 skView.multipleTouchEnabled = true