0
我有一個名爲Player的SKNode的子類,它幾乎包括這個:http://hub.ae/blog/2014/03/26/soft-body-physics-jellyusing-spritekit/轉換爲swift(有一些變化)。我允許用戶用他的手指用下面的代碼移動玩家節點:locationInNode返回錯誤的結果
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
player.runAction(SKAction.moveTo(touch.locationInNode(world), duration: 1))
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
player.runAction(SKAction.moveTo(touch.locationInNode(world), duration: 1))
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
player.removeAllActions()
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
player.removeAllActions()
}
*作爲一個說明,在「世界」變種你看到的只是另一個SKNode。 'player'是這個節點的孩子。
這看起來應該可以工作,但是節點會沿非常奇怪的方向移動。這是它的外觀示例: http://gyazo.com/87b0d09101bbbfd3ac0f2a3cdbf42e4c
我該如何解決這個問題?我發現將場景的定位點設置爲0.5可以解決此問題,但是,'player'節點的物理主體會變得混亂。
這部分工作。當我點擊播放器節點上方時,它會向錯誤的方向移動,但是當我點擊它時,節點會正確移動。 下面是發生了什麼的示例:http://gyazo.com/b968913c3ebd482dbc20bf54b869d071 我很感激幫助。 – Aaron
您是否檢查了觸摸的座標?他們是否正確? 必須嘗試'moveBy'動作? – Darvydas
經過一番調查,我認爲也許問題是我的'節點中心'功能(這被稱爲將相機對準播放器)。我相信這正在改變正確的座標(並且在沒有運行該功能的情況下進行測試後,它似乎正在工作)。你知道解決這個問題的方法嗎?功能在這裏:http://pastebin.com/QRpQmLab(由於字符限制而粘貼) – Aaron