0
SKSceneでユーザーが画面の左または右のいずれかにタッチしているかどうかを検出しようとしています。画面の半分がタッチされていることを認識しないスウィフトタッチ認識
私は次のコードをまとめましたが、どこに触れても「左」を出力するだけです。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
if(location.x < self.frame.size.width/2){
print("Left")
}
else if(location.x > self.frame.size.width/2){
print("Right")
}
}
}
ありがとうございました!!これで私の髪を引っ張ってきた。 –
frame.midXを使用すると、アンカーポイントに関係なく、これを少しきれいにすることができます。 "location.x
crashoverride777