2015-12-21 58 views
1

在手指的場景中,您可以移動物體。但是,如果你只是加快手指在屏幕上的移動 - 物體仍然保持原位。是否有可能加快其運動的速度?時間已被設置爲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) 
    } 
} 

回答

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) 

}