7

How do I turn off interaction for a childnode?

I'm adding labels to a bunch of sprites, beneath the sprite, describing what they are. The sprites themselves are touchable, and have code that responds when touchesBegun etc.

The labels do not visually overlap the sprite, they're fully beneath the visual representation of the Sprites, but they are children of their respective Sprite, and I'd like to keep it that way.

But I don't want the labels to respond to touch.

I set the labels to

myLabel.isUserInteractionEnabled = false

But this doesn't make any difference, they're still responding to touch as if they're the Sprite.

Confused
  • 6,048
  • 6
  • 34
  • 75
  • Try `label.isPaused = true`. No idea if it will work, but I feel like it could do something... – Nik Oct 13 '16 at 22:30

1 Answers1

1

By default isUserInteractionEnabled is false then the touch on a child like a SKLabelNode is, by default, a simple touch handled to the main (or parent) class (the object is here, exist but if you don't implement any action, you simply touch it)

If you set the userInteractionEnabled property to true on a subclassed SKNode then the touch delegates will called inside this specific class. So, you can handle the touch for the label (as your case) within its class.

Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133