Ryan Detzel
Ryan Detzel

Reputation: 5599

Adding child SKNode to existing SKNode changes the touch area

I'm create a SKNode to the scene and logging touch events on each individual SKNode. I can add as many as I want and the touches work as expected, if I touch the node and only the visible node do I see the log messages. Now, if I add another SKShapeNode to any of the previous SKNode's the touch area expands to be more of a rectangle and now I see the log message even if I touch outside the origin SKNode.

The first picture shows the original touch area of the SKNode and the second is the new touch area after adding a child SKShapeNode to that SKNode. The SKShapeNode being added is 20x20 so it fits within the 20x100 bar.

The problem is I now get multiple touch events when touching the other bars since they overlap. Is there any way around this?

Touch area shown in blue for that SKNode New touch area after adding a child SKShapeNode

Upvotes: 0

Views: 129

Answers (1)

sangony
sangony

Reputation: 11696

You appear to be using separate graphics for each angle of your line. Instead try using the same graphic with your line at 0 degrees and then using the zRotation to angle it. I have not tried this myself but I think it will fix your issue.

Alternately try using containsPoint for your touch recognition in the touchesBegan method. You can check if the touch is within any of the nodes and process accordingly.

Upvotes: 2

Related Questions