我正在创建一个2x2矩阵,并将节点放入其中。当我在矩阵的某个位置中选择一个节点时,他使用着色操作将其颜色更改为红色。
问题是,如果节点图像太大,即使我在矩阵的另一个方格中触摸,他也会识别出触摸。
例如:
[0-0][0-1]
[1-0][y]我的节点位于Y方格(位置: 1-1)。如果图像大于正方形的大小,即使我点击1-0正方形,他也会得到触摸。
我不能用节点的矩阵位置来获得触摸,因为图像与它重叠,所以它永远不会触及矩阵方格。
无论如何,我是否可以使用节点的PhyshicsBody而不是
let location = touch.locationInNode(self)
let node = nodeAtPoint(location)发布于 2015-09-14 23:13:24
如果我理解你的问题。
我知道你需要油漆元素符合触摸位置。
我所做的,在这个例子中我是以场景为参照,但是你可以和别人一起做雪碧,嗯,我把我的屏幕切成4片,我得到了触点并验证了场景中的位置。
class test:SKScene{
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
if let touch = touches.first as? UITouch{
let touchLocation = touch.locationInNode(self)
if touchLocation.x < self.size.width/2 && touchLocation.y < self.size.height/2 {
//paint red [1,0]
}else if touchLocation.x < self.size.width/2 && touchLocation.y > self.size.height/2 {
//paint red [0,0]
}else if touchLocation.x > self.size.width/2 && touchLocation.y > self.size.height/2 {
//paint red [0,1]
}else if touchLocation.x > self.size.width/2 && touchLocation.y < self.size.height/2 {
//paint red [1,1]
}
}
}
}希望帮了你..。
https://stackoverflow.com/questions/32575206
复制相似问题