Confused
Confused

Reputation: 6278

Add label to SKSpriteNode without it being touchable

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.

Upvotes: 7

Views: 344

Answers (1)

Alessandro Ornano
Alessandro Ornano

Reputation: 35392

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.

Upvotes: 1

Related Questions