我创建了一个 SKSpriteNode,其中 Emitter 作为子级
onObject: SKSpriteNode! = SPSpriteNode(texture: ballTexture)
onObject.physicsBody = SKPhysicsBody(circleOfRadius: (ballSize / 2) * 0.99)
onObject.physicsBody?.affectedByGravity = true
onObject.physicsBody?.allowsRotation = true
onObject.physicsBody?.isDynamic = true
onObject.physicsBody?.mass = 3
onObject.physicsBody?.angularDamping = 1
onObject.physicsBody?.angularVelocity = ballRotation
onObject.physicsBody?.applyAngularImpulse(ballRotation)
onObject.physicsBody?.restitution = 0.5
let particles = SKEmitterNode(fileNamed: "emitter.sks")
particles?.zPosition = onObject.zPosition - 1
particles?.particleZPosition = onObject.zPosition - 1
particles?.position = CGPoint(x: 0, y: 0)
particles?.targetNode = self
particles?.particlePositionRange.dx = onObject.size.width
particles?.particlePositionRange.dy = onObject.size.height
particles?.name = "particles"
particles?.isUserInteractionEnabled = false
onObject.addChild(particles!)
但是如果我触摸发射器,即使用户交互被禁用,动作也会被触发?!
我该如何解决?
我已经尝试忽略touched.name(粒子),但它似乎不起作用,因为每次我触摸粒子或它附近的任何地方时,父节点也会获得触摸事件。
我怎么能防止这种情况?
我正在检查触摸事件
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first!
let positionInScene = touch.location(in: self)
let touchedNodes = self.nodes(at: positionInScene)
print(touchedNode.name)
if ((touchedNode.name?.range(of: powerUps.POWERUPS)) != nil){
print("powerUp Touched")
}
}