Question

In my game, I'm trying to determine what points to dole out depending on where an arrow hits a target. I've got the physics and collisions worked out and I've decided to draw several nested circular SKShapeNodes to represent the different rings of the target.

I'm just having issues working out the logic involved in checking if the contact point coordinates are in one of the circle nodes...

Is it even possible?

Was it helpful?

Solution

The easiest solution specific to Sprite Kit is to use the SKPhysicsWorld method bodyAtPoint:, assuming all of the SKShapeNode also have an appropriate SKPhysicsBody.

For example:

SKPhysicsBody* body = [self.scene.physicsWorld bodyAtPoint:CGPointMake(100, 200)];
if (body != nil)
{
    // your cat content here ...
}

If there could be overlapping bodies at the same point you can enumerate them with enumerateBodiesAtPoint:usingBlock:

OTHER TIPS

You can also compare the SKShapeNode's path with your CGPoint.

SKShapeNode node; // let there be your node
CGPoint point;   // let there be your point

if (CGPathContainsPoint(node.path, NULL, point, NO)) {
   // yepp, that point is inside of that shape
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top