我想要做的就是能够在屏幕上拖放一个精灵。我试过下面的代码:如何在Swift 3.0中拖放一个精灵?
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使用你的包含点代码来启动一个激活状态,然后你使用touchesMoved,如果状态被激活,你只是移动球,你不检查点,然后在touchesEnded或touchesCanceled,你停用它 – Knight0fDragon