1
votes

I have a moving SKSpriteNode where i detect taps on the scene with TouchesBegan based on the nodes name. This worked perfectly, until i addeed a SKEmitterNode as a child to the moving node leaving a trail of circles behind the moving node.

My touches on the main/parent node is now detected when the SKEmitterNode particle trail is being touched.

How can i only detect touches on my main/parent spritenode, but not on the child nodes of this sprite?

When the sparks that ouside node1.size is tapped, why is "node1" returned in touchesbegan and not "emitter"?

Example GameScene.swift

 override func didMoveToView(view: SKView) {

    let node1 = SKSpriteNode(color: SKColor.redColor(), size: CGSizeMake(400, 300))
    node1.position = CGPointMake(size.width/2, size.height/2)
    node1.name = "node1"
    addChild(node1)

    let emitter = SKEmitterNode(fileNamed: "MyParticle.sks")
    emitter.name = "emitter"
    emitter.zPosition = -1
    node1.addChild(emitter)

}


override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    /* Called when a touch begins */
    let touch: UITouch = touches.anyObject() as UITouch
    let location = touch.locationInNode(self)

    let touchedNode = nodeAtPoint(location)

    println(touchedNode.name)
}
1
can you set the userInetractionEnabled property for each nodeuser4233369
I have tried, its not working. Think it's because im not interacting with the nodes, just checking which nodes are where at a current location in my scene.Espen Birk
your code will not work on swift 2.0!wm.p1us

1 Answers

1
votes

Solved it setting the SKEmitterNode´s targetnode property to another node other than the one im detecting taps on.

https://developer.apple.com/library/mac/Documentation/SpriteKit/Reference/SKEmitterNode_Ref/index.html#//apple_ref/occ/instp/SKEmitterNode/targetNode

emitter.targetNode = self.scene