I have a UITapGestureRecognizer and a UIPanGestureRecognizer on a UIView with SKScene on it. The gesture recognition drive moves the SKNode from left to right, and I want the Tap gesture recognizer to detect a child SKNode that works. Panning works fine, but I'm having trouble detecting taps - Tap Gesture launches the appropriate method, but I'm not sure how to convert the coordinates from the view to the scene in node to detect one of the child nodes.
UIView (with gestures) → SKScene → Panning node → Children panning node
How to check if the touch coordinate of the hard disk matches any given SKNode?
-(void)tapAction:(UITapGestureRecognizer*)sender{ if (sender.state == UIGestureRecognizerStateEnded) { // handling code CGPoint touchLocation = [sender locationOfTouch:0 inView:sender.view]; NSLog(@"TAP %@", NSStringFromCGPoint(touchLocation) ); for (SKLabelNode *node in _containerNode.children) { if ([node containsPoint:[node convertPoint:touchLocation fromNode:self.parent]]) { //This is where I want the tap to be detected. } CGPoint checkPoint = [node convertPoint:touchLocation fromNode:self.scene]; NSLog(@"CheckPoint %@", NSStringFromCGPoint(checkPoint) ); //NSLog(@"iterating nodes"); if ([node containsPoint:checkPoint]) { NSLog(@"touch match %@", node); } } }
}
source share