我有一个平坦地形的球,但是我试图根据用户的触摸屏位置来移动球,所以当用户在屏幕上的任何地方点击时,我都会将球移动到触摸屏的X位置
我的代码:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
if (ball?.hasActions())! {
ball?.removeAllActions()
}
let moveBY = SKAction.moveBy(x: touch.location(in: view).x, y: 70, duration: 1)
self.ball?.run(moveBY)
}
}然而,当用户在屏幕上点击时,球会相应地移动,但当第二次点击时,球不会根据触摸的X移动
https://stackoverflow.com/questions/47922263
复制相似问题