SpriteKit:检测 UILongPressGestureRecognizer 是否点击了子节点
SpriteKit: detect if UILongPressGestureRecognizer tapped child node
我想检测我的节点是否被窃听。我正在使用 UIGestureRecognizer:
let longPress = UILongPressGestureRecognizer()
longPress.minimumPressDuration = CFTimeInterval(0.0)
longPress.addTarget(self, action: #selector(self.longPressGesture(longpressGest:)))
self.view?.addGestureRecognizer(longPress)
以及调用的函数:
@objc func longPressGesture(longpressGest: UIGestureRecognizer) {
let touchPos = longpressGest.location(in: self.view)
if atPoint(touchPos).name == "jump" {
print("jump")
}
}
我希望在点击时被检测到的按钮:
let jump = SKSpriteNode(imageNamed: "Any")
jump = CGSize(width: self.size.width*0.06, height: self.size.height*0.08)
jump = CGPoint(x: self.size.width*0.05 - self.size.width/2, y: self.size.height*0.1 - self.size.height/2)
jump.zPosition = 2
jump.name = "jump"
cameraNode.addChild(jump)
Importend: jump 是我的 cameraNode
的子节点
我的相机节点:
self.camera = cameraNode
self.addChild(cameraNode)
let cameraNode = SKCameraNode()
let range = SKRange(constantValue: 0)
let cameraConstraint = SKConstraint.distance(range, to: player)
cameraNode.constraints = [cameraConstraint]
使用此代码 "jump" 不会打印。我想我必须将 touchPos 转换为与 cameraNodes 或跳转按钮系统相同的坐标系。 我的问题:如何将视图坐标转换为我的 cameraNodes 坐标系?
P.S。我已经尝试了没有用的整个转换功能。也许我只是做错了。
SKNodes 有一个方法叫做 convertPoint
@objc func longPressGesture(longpressGest: UIGestureRecognizer) {
let touchPosinView = longpressGest.location(in: self.view)
let touchPos = self.convertPoint(fromView:touchPosinView )
if atPoint(touchPos).name == "jump" {
print("jump")
}
}
我想检测我的节点是否被窃听。我正在使用 UIGestureRecognizer:
let longPress = UILongPressGestureRecognizer()
longPress.minimumPressDuration = CFTimeInterval(0.0)
longPress.addTarget(self, action: #selector(self.longPressGesture(longpressGest:)))
self.view?.addGestureRecognizer(longPress)
以及调用的函数:
@objc func longPressGesture(longpressGest: UIGestureRecognizer) {
let touchPos = longpressGest.location(in: self.view)
if atPoint(touchPos).name == "jump" {
print("jump")
}
}
我希望在点击时被检测到的按钮:
let jump = SKSpriteNode(imageNamed: "Any")
jump = CGSize(width: self.size.width*0.06, height: self.size.height*0.08)
jump = CGPoint(x: self.size.width*0.05 - self.size.width/2, y: self.size.height*0.1 - self.size.height/2)
jump.zPosition = 2
jump.name = "jump"
cameraNode.addChild(jump)
Importend: jump 是我的 cameraNode
的子节点我的相机节点:
self.camera = cameraNode
self.addChild(cameraNode)
let cameraNode = SKCameraNode()
let range = SKRange(constantValue: 0)
let cameraConstraint = SKConstraint.distance(range, to: player)
cameraNode.constraints = [cameraConstraint]
使用此代码 "jump" 不会打印。我想我必须将 touchPos 转换为与 cameraNodes 或跳转按钮系统相同的坐标系。 我的问题:如何将视图坐标转换为我的 cameraNodes 坐标系?
P.S。我已经尝试了没有用的整个转换功能。也许我只是做错了。
SKNodes 有一个方法叫做 convertPoint
@objc func longPressGesture(longpressGest: UIGestureRecognizer) {
let touchPosinView = longpressGest.location(in: self.view)
let touchPos = self.convertPoint(fromView:touchPosinView )
if atPoint(touchPos).name == "jump" {
print("jump")
}
}