0

I need to handle the touch and not consume it. Is it possible to perform in SpriteKit? I would like to keep code as generic as possible.

Following the documentation I tried this:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //Do some work with the touch

    //Forward it to next responder(node bellow)
    [super touchesBegan:touches withEvent:event];
}

But touches don't get forwarded.

My class is subclass of SKNode.

Dobroćudni Tapir
  • 3,082
  • 20
  • 37
  • Post a link to the documentation. – trojanfoe Jan 24 '14 at 10:08
  • The link you provided has nothing to do with SpriteKit. – trojanfoe Jan 24 '14 at 10:10
  • @trojanfoe SKNode is subclass of UIResponder – Dobroćudni Tapir Jan 24 '14 at 10:11
  • Well your question is confusing then. On the one hand you talk about the node's parent (a SpriteKit concept) and on the other you want to use generic OO techniques for passing a touch event to the superclass. Are you confusing superclass and parent as being the same thing? – trojanfoe Jan 24 '14 at 10:13
  • As SKNode states - > Inherits from UIResponder : NSObject – Dobroćudni Tapir Jan 24 '14 at 10:15
  • Are you confusing superclass and parent node as being the same thing? – trojanfoe Jan 24 '14 at 10:16
  • Super class of SKNode is UIResponder. I know the difference between those two. And parent is another node within the scene. I want the touch to be forwarded to it. Documentation(UIResponder touchesBegan:withEvent:) states I should call super instead of sending the touch myself. – Dobroćudni Tapir Jan 24 '14 at 10:17
  • Check out this question: http://stackoverflow.com/questions/19237616/how-to-turn-off-user-interaction-of-child-node-when-parent-node-has-it-enabled-i – Andrey Gordeev Jan 24 '14 at 10:55

1 Answers1

1

Simple:

[self.parent touchesBegan:touches withEvent:event];

The next responder is always another view, not another node. If the direct parent is not the node you want to send it to, then do self.parent.parent or self.parent.parent.parent if you know that the right node is the n-th parent of the node receiving the touch. Otherwise use the node search functionality to find the right node.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Problem is that the parent isn't next responder :( – Dobroćudni Tapir Jan 24 '14 at 14:12
  • You said you needed it to be passed to the parent. The next responder is always another view, not another node. If the direct parent is not the node you want to send it to, then do self.parent.parent or self.parent.parent.parent if you know that the right node is the n-th parent of the node receiving the touch. Otherwise use the node search functionality to find the right node. – CodeSmile Jan 24 '14 at 15:15
  • I edited my question to be clear. Your comment answers it perfectly, could you edit your answer so I can accept it. – Dobroćudni Tapir Jan 24 '14 at 16:38