【发布时间】:2020-11-04 21:58:16
【问题描述】:
我正在尝试用手指更准确地拖动 SKSprite 节点或 UIImage。例如,如果在节点的底角注册并移动了触摸,我希望图像保持您的手指位置与节点中心之间的距离。当前中心位置跳转到手指位置。
这是我的代码,似乎没有维护偏移代码(touchl - previousLocation)。 有什么建议吗?
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let touchl = touch.location(in: self)
let previousLocation = touch.previousLocation(in: self)
triangle.position.x = touchl.x + (touchl.x - previousLocation.x)
triangle.position.y = touchl.y + (touchl.y - previousLocation.y)
}
}
【问题讨论】:
标签: swift xcode sprite-kit uikit draggable