【发布时间】:2016-08-17 19:15:24
【问题描述】:
我想要做的就是能够在屏幕上拖放一个精灵。我试过以下代码:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in (touches ) {
let location = touch.locationInNode(self)
if ball.containsPoint(location) {
ball.position = location
}
}
}
此代码确实有效,但是,当我快速拖动球时,我猜它检测到“球”不再包含点“位置”并且球停止了,这意味着我又捡起了球。我希望球能够快速响应我的触球,这样球就不会停止移动。我该怎么做?
【问题讨论】:
-
因为你需要从逻辑上考虑,如果你快速移动,你的手指在检查时不再接触球。您需要使用 touchesBegan 使用您的 containsPoint 代码启动激活状态,然后使用 touchesMoved,如果状态已激活,您只需移动球,您不检查该点,然后在 touchesEnded 或 touchesCanceled 上,您将其停用
标签: swift sprite-kit sprite swift3