【发布时间】:2015-05-19 17:45:49
【问题描述】:
我有一个名为 Player 的 SKNode 子类,它几乎包含以下内容:http://hub.ae/blog/2014/03/26/soft-body-physics-jellyusing-spritekit/ 转换为 swift(进行了一些更改)。我已经允许用户使用以下代码用手指移动播放器节点:
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 可以解决此问题,但是“玩家”节点的物理主体会变得混乱。
【问题讨论】:
标签: ios swift sprite-kit