Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 700
Confused Avatar asked Oct 13 '16 03:10

Confused


Video Answer


1 Answers

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.

like image 88
Alessandro Ornano Avatar answered Oct 07 '22 10:10

Alessandro Ornano