1
私は、プレイヤーがタッチに移動して(タッチが動くと宛先を更新する)ゲームを持っています。タッチが動いていない間にカメラが動くまで指は完全に動きます(指は画面上に静止しているので、touchMoved
でもtouchesEnded
も呼び出されません)。プレイヤーは開始位置に関して正しい位置に移動しますが、移動に関しては移動しませんカメラ。 (私は、カメラのフレームの位置を保存したくありません。もしそれがうまくいけば、画面の片側にあるタップは、 ayerを世界の終わりに移動させるでしょう)Swift SpriteKit:指が止まってカメラが動いたときにTouchesMovedが更新されない
ここでのコードのむき出しの骨だ:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
location = touch.location(in: self)
player.goto = location
player.moving = true
}}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
player.goto = location
player.moving = true
}}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
player.goto = location
player.moving = true
}}
override func update(_ currentTime: CFTimeInterval) {
if player.position.x > w_screen/2 && player.position.x < (lab.size.width-w_screen/2) {
cameranode.position.x = player.position.x
}
if player.moving == true {
v = CGVector(dx: player.goto.x-player.position.x, dy: player.goto.y-player.position.y)
d = sqrt(v.dx*v.dx + v.dy*v.dy)
vel = 400*atan(d/20)/1.57
if vel>1 { player.physicsBody!.velocity = CGVector(dx: v.dx*vel/d, dy: v.dy*vel/d) } else {
player.moving = false
player.physicsBody!.velocity = CGVector.zero
}}
ご協力いただければ幸いです。