2

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?

4

2 回答 2

3

Sprite Kit 最简单的解决方案是使用 SKPhysicsWorld 方法bodyAtPoint:,假设所有的 SKShapeNode 也有一个合适的 SKPhysicsBody。

例如:

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

如果同一点可能有重叠的主体,您可以使用 enumerateBodiesAtPoint:usingBlock:

于 2014-06-03T11:49:06.683 回答
3

您还可以将SKShapeNode's 路径与您的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
}
于 2015-11-03T08:40:51.700 回答