Move two paddles at same time in SpriteKit + Swift

二次信任 提交于 2019-12-24 13:35:37

问题


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
 }

回答1:


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


来源:https://stackoverflow.com/questions/33194394/move-two-paddles-at-same-time-in-spritekit-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!