Search code examples
iosswiftsprite-kitcollision-detection

How to enforce touching within a ring shape using iOS SpriteKit?


I need to have the player moving the finger within the shaded ring: enter image description here

The program should be able to detect "out of boundary" events once the finger moves outside the ring (shown in red).

Any best practices for doing this in SpriteKit, ideally in Swift? Thanks!


Solution

  • You could draw your shapes using CGPath, then use CGPathContainsPoint to determine if the touched locations are inside or outside the path.

    You can use CGPaths like this in SpriteKit using SKShapeNode.