私のゲームでは、ノードをドラッグ、スワイプ、フリックすることができます。しかし、私はユーザーにノードをスワイプ/フリックできるようにしたいので、ユーザーがノードをドラッグできるようにしたくありません。これどうやってするの?ここでスプライトをドラッグせずにフリック/スワイプするにはどうすればよいですか?
は私の現在のコードです:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
if ball.frame.contains(location) {
touchPoint = location
touching = true
}
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first as UITouch!
let location = touch!.location(in: self)
touchPoint = location
for touch in touches {
let location = touch.location(in: self)
touchPoint = location
if touching {
if touchPoint != ball.position {
let dt:CGFloat = 1.0/60.0
let distance = CGVector(dx: touchPoint.x-ball.position.x, dy: touchPoint.y-ball.position.y)
let velocity = CGVector(dx: distance.dx/dt, dy: distance.dy/dt)
ball.physicsBody!.velocity=velocity
}
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
touching = false
for touch in touches {
let location = touch.location(in: self)
touchPoint = location
let node = self.atPoint(location)
}
}
達成したいことを明確にしてください。 – matthiaswitt
あなたの目標は、指がスワイプジェスチャーから解放されるまでノードが動かないようにすることです。その時点で、指の動きの速度と距離が画面全体でノードの移動速度と方向を決定します。 – Confused