[英]Swift - PanGesture Recognizer - move with object - speed of movement
[英]How to speed up the movement of the object?
在手指的場景中,您可以移動對象。 但是,如果只是加快手指在屏幕上的移動,則該對象將保持在原位。 是否可以加快其運動速度? 持續時間已設置為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)
}
}
問題不在於速度,而是問題在於您在屏幕上的移動速度如此之快,觸摸不再能夠識別其下方的節點,因為該節點實際上不在其下方。 處理該問題的方法是在touch begin事件上,檢查一個節點,然后將此節點分配給變量。 然后在觸摸移動事件中,更新新變量。 最后在觸摸端,清除變量。 請注意,您需要處理此類代碼以實現多點觸控
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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.