【发布时间】:2018-05-25 11:52:57
【问题描述】:
我有一个精灵套件游戏,我想知道用户是否触摸了屏幕的左侧、右侧或中间 (25/50/25)
当我触摸屏幕的最左侧时,它说我在 x 轴上触摸 -450,而它应该是 0。我假设它获得了相对于场景的触摸位置,并且随着锚点开始向右 450 像素,当我触摸 0 时给我 -450。
由于这是一个横向滚动条,移动锚点不起作用,我需要屏幕的触摸位置:
override func touchesBegan(_ touches: Set<UITouch>,with event: UIEvent?){
var touchLeft : Bool = false
var touchRight : Bool = false
var touchMiddle : Bool = false
for touch in (touches) {
let location = touch.location(in: self)
if(location.x < self.size.width/4){
touchLeft = true
print("Left")
} else if(location.x > ((self.size.width/4) * 3)){
touchRight = true
print("Right")
} else {
touchMiddle = true
print("Middle")
}
}
}
【问题讨论】:
-
@vacawama,你把
Views和Nodes/Scenes混淆了
标签: ios swift sprite-kit uitouch