如何加快物体的运动?

时间:2015-12-21 16:57:52

标签: ios swift sprite-kit skaction

在手指的场景中,您可以移动对象。但是如果你只是加速手指在屏幕上的移动 - 物体就会保留在原位。是否有可能加快其运动速度?持续时间已设置为0

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {

    let touch = touches.first
    let touchLocation = touch!.locationInNode(self)
    let node = self.nodeAtPoint(touchLocation)

    if (node.name == "circle") {

        let moveAction = SKAction.moveTo(touchLocation, duration: 0)

        figureUser.runAction(moveAction)
    }
}

1 个答案:

答案 0 :(得分:0)

你的问题不在于速度,你的问题是你在屏幕上移动如此之快,以至于你的触摸不再识别它下面的节点,因为节点实际上不在它下面。如何处理此问题是在触摸开始事件,您检查节点,并将此节点分配给变量。然后在触摸移动事件中,更新新变量。最后在触摸结束时,清除变量。请注意,您需要处理此代码,例如多点触控

var movingNode : SKNode?
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)     {

    let touch = touches.first
    let touchLocation = touch!.locationInNode(self)
    let node = self.nodeAtPoint(touchLocation)

    if (node.name == "circle") {
        movingNode = node
        let moveAction = SKAction.moveTo(touchLocation, duration: 0)

        figureUser.runAction(moveAction)
    }
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?)     {

    let touch = touches.first
    let touchLocation = touch!.locationInNode(self)

        let moveAction = SKAction.moveTo(touchLocation, duration: 0)
     //at this point I am lost,  how does node even relate here,  
     //is figureUser suppose to be node?
        figureUser.runAction(moveAction)

}