Search code examples
iossprite-kittouchtouchesbegantouchesmoved

SpriteKit - How can I catch the event when the touch moves over a sprite, but didn't actually begin on the sprite


In SpriteKit, I want to catch event when touch moves over a sprite, but hasn't actually started on this sprite, but on another piece of SKScene.

I can catch touchesBegan inside the SKSpriteNode A if the touch starts on it and then dragged over it, but not when touch started on another node - B - and then dragged over my node - A. Anyone knows how to catch this one, because I think I am doing something wrong here.


Solution

  • Thanks @Christian W. but I have a simpleer solution for now, although it is not what I had on mind actually: Just put this in Scene and catch the touchesMoved inside it, having this code inside it:

    SKNode * draggedOverNode = [self nodeAtPoint:location];
    [draggedOverNode touchesMoved:touches withEvent:event];
    

    And implement the touchesMoved function inside that object that actually extends the SKNode (which most of your classes will do).