Search code examples
iossprite-kit2d-games

Detect that SKShapedNode is closed


In my future game(in SpriteKit), I need to draw circle-like shapes. I use CGMutablePathRef and SKShapeNode for drawing itself.

On touchesEnded I need to check if the user did close the circle or if there is a gap between start and end touches. (Strictly saying, it can be not only the right circle, I need to detect any closed shape, e.g. loop...)

How can I do this checking?


Solution

    1. Store the touches locations (points) in an array: [yourArray addObject:[NSValue valueWithCGPoint:yourPoint]];
    2. Make a rect (size? your choice! the smaller it is, the more precise) around the first point in the array (first touch location).
    3. Control if the rect also contains the last point in the array (last touch location).
    4. If so, then close your path.