Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SpriteKit&x2B;敏捷的_Ios_Swift_Sprite Kit - Fatal编程技术网

Ios SpriteKit&x2B;敏捷的

Ios SpriteKit&x2B;敏捷的,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我正在用SpriteKit+Swift制作一个简单的乒乓球游戏。我只能在同一时间移动每一个桨,显示屏上只有一个手指。我已经看到了其他相关的问题,但它们对我没有帮助。我的代码: override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { let touch = touches.first as UITouch? let touchLocation = touch?.loca

我正在用SpriteKit+Swift制作一个简单的乒乓球游戏。我只能在同一时间移动每一个桨,显示屏上只有一个手指。我已经看到了其他相关的问题,但它们对我没有帮助。我的代码:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    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
    }

    if body?.node!.name == PaddleCategoryName2 {
        print("Paddle2 Touched!")
        fingerIsOnPaddle2 = true
    }


}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    if fingerIsOnPaddle {
        let touch = touches.first as UITouch?
        let touchLocation = touch?.locationInNode(self)
        let previousTouchLocation = touch?.previousLocationInNode(self)

        let paddle = self.childNodeWithName(PaddleCategoryName) as! SKSpriteNode

        var newYPosition = paddle.position.y + (touchLocation!.y - previousTouchLocation!.y)

        newYPosition = max(paddle.size.height / 2, newYPosition)
        newYPosition = min(self.size.height - paddle.size.height / 2, newYPosition)

        paddle.position = CGPointMake(paddle.position.x, newYPosition)

    }

    if fingerIsOnPaddle2 {
        let touch = touches.first as UITouch?
        let touchLocation = touch?.locationInNode(self)
        let previousTouchLocation = touch?.previousLocationInNode(self)

        let paddle2 = self.childNodeWithName(PaddleCategoryName2) as! SKSpriteNode

        var newYPosition = paddle2.position.y + (touchLocation!.y - previousTouchLocation!.y)

        newYPosition = max(paddle2.size.height / 2, newYPosition)
        newYPosition = min(self.size.height - paddle2.size.height / 2, newYPosition)

        paddle2.position = CGPointMake(paddle2.position.x, newYPosition)
    }
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    fingerIsOnPaddle = false
    fingerIsOnPaddle2 = false
}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
让触摸=触摸。首先作为UITouch?
让touchLocation=touch?.locationInNode(自身)
让body:SKPhysicsBody?=self.physicsWorld.bodyAtPoint(触摸位置!)
如果body?.node!.name==PaddleCategoryName{
打印(“触桨!”)
fingerIsOnPaddle=true
}
如果body?.node!.name==PaddleCategoryName2{
打印(“触屏2!”)
fingerIsOnPaddle2=true
}
}
覆盖功能触摸移动(触摸:设置,带事件:UIEvent?){
如果fingerIsOnPaddle{
让触摸=触摸。首先作为UITouch?
让touchLocation=touch?.locationInNode(自身)
让previousTouchLocation=触摸?.previousLocationInNode(自身)
让paile=self.childNodeWithName(PaileCategoryName)作为!SKSpriteNode
var newYPosition=blade.position.y+(touchLocation!.y-previousTouchLocation!.y)
newYPosition=max(桨叶大小高度/2,newYPosition)
newYPosition=min(self.size.height-patle.size.height/2,newYPosition)
桨位置=CGPointMake(桨位置x,新位置)
}
如果fingerIsOnPaddle2{
让触摸=触摸。首先作为UITouch?
让touchLocation=touch?.locationInNode(自身)
让previousTouchLocation=触摸?.previousLocationInNode(自身)
让Papper2=self.childNodeWithName(PapperCategoryName2)作为!SKSpriteNode
var newYPosition=palle2.position.y+(touchLocation!.y-previousTouchLocation!.y)
新位置=最大值(桨叶2.size.height/2,新位置)
newYPosition=min(self.size.height-桨叶2.size.height/2,newYPosition)
桨叶2.position=CGPointMake(桨叶2.position.x,新位置)
}
}
覆盖func touchesEnded(触摸:设置,withEvent事件:UIEvent?){
fingerIsOnPaddle=false
fingerIsOnPaddle2=false
}

我知道这有点晚了,但我想我会尽量减少将来对任何人的麻烦

我这样做的方式是首先移除

let touch = touches.first as UITouch?
然后将您的整个touchesMoved功能放在这段代码中:

for touch in touches
{

}

您现在可以像使用原始touch一样使用touch,但将实现多点触摸。

我知道这有点晚了,但我想我会尽量减少未来任何人的麻烦

我这样做的方式是首先移除

let touch = touches.first as UITouch?
然后将您的整个touchesMoved功能放在这段代码中:

for touch in touches
{

}

您现在可以像使用原始触摸屏一样使用触摸屏,但将实现多点触摸。

这应该是您想要的,这应该是您想要的