My solution does not require the use of isKindOfClass things ...
In your SKScene interface:
@property (nonatomic, strong) SKNode* touchTargetNode;
In the implementation of SKScene
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touch = [touches anyObject]; NSArray* nodes = [self nodesAtPoint:[touch locationInNode:self]]; self.touchTargetNode = nil; for( SKNode* node in [nodes reverseObjectEnumerator] ) { if( [node conformsToProtocol:@protocol(CSTouchableNode)] ) { SKNode<CSTouchableNode>* touchable = (SKNode<CSTouchableNode>*)node; if( touchable.wantsTouchEvents ) { self.touchTargetNode = node; [node touchesBegan:touches withEvent:event]; break; } } } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [self.touchTargetNode touchesCancelled:touches withEvent:event]; self.touchTargetNode = nil; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [self.touchTargetNode touchesMoved:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self.touchTargetNode touchesEnded:touches withEvent:event]; self.touchTargetNode = nil; }
You will need to define the CSTouchableNode protocol ... name it whatever you like :)
@protocol CSTouchableNode <NSObject> - (BOOL) wantsTouchEvents; - (void) setWantsTouchEvents:(BOOL)wantsTouchEvents; @end
For your SKNodes that you want to be tangible, they must comply with the CSTouchableNode protocol. You will need to add something like below to your classes as needed.
@property (nonatomic, assign) BOOL wantsTouchEvents;
Performing this, click on the nodes, as I expect it to work. And it should not break when Apple fixes the "userInteractionEnabled" error. And yes, this is a mistake. Dumb mistake. Stupid Apple.
Update
There is another mistake in SpriteKit ... the order of the z nodes is strange. I saw strange node ordering ... so I try to force zPosition for nodes / scenes that need it.
I updated the SKScene implementation for sorting nodes based on zPosition.
nodes = [nodes sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"zPosition" ascending:false]]]; for( SKNode* node in nodes ) { ... }
Automatontec
source share