IOS7 Sprite Kit, how to disable touch on the sprite so that it “skips”?

I know that for traditional UIView, I can check the box "enable user interaction" in "NO", and the view will no longer respond to touches, allowing those underneath to see the strokes.

Is there a way to implement the same scroll functions in the Sprite Kit? While I saw people using Touches get started, understand the meaning and ask the scene about the nodes at this point.

The problem with this approach is that if I want to add overlays on top of sprites (for example, monster life points, etc.), they will also respond to touch. So far I am trying to avoid this problem by creating custom classes for different nodes, and then having a very large if statement, checking the class of each node.

Is there a better way to achieve cross-cutting functionality for a set of sprites?

+6
source share
2 answers

If you set the userInteractionEnabled property to YES in a subclass of SKSpriteNode, then touch delegates will call inside the class. Consequently, you can handle the touch for sprite in your class.

However, by default, the userInteractionEnabled property userInteractionEnabled set to NO . Therefore, touching the sprite by default is a "scroll".

So, for the required overlays, create custom classes for sprites, implement touchesBegan: and other delegates inside this class, and when initializing set the userInteractionEnabled property to YES .

+16
source

The Sprite Kit uses the zPosition value only to determine the impact test and drawing order.

So you can put all your sprites above 0 if you don't want to hit them. And then such a simple logical test is zPostion> 0

+6
source

All Articles