使用 self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopF​​romPath:

using self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:

我想用

 self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:(CGPathRef)];

在 spriteKit 中,但我不确定如何去做。我用谷歌搜索了如何创建路径,但找不到太多然后当我制作了 UIBezierPath 时,我无法弄清楚如何将它更改为 CGPath,然后在 about 中使用它。我想用这些点来创建路径 (91,6),(184,222),(2,222) 然后回到 (91,6) 来创建一个三角形。谁能帮帮我。

下面是一个使用路径创建物理体的例子:

CGMutablePathRef trianglePath = CGPathCreateMutable();
CGPathMoveToPoint(trianglePath, nil, 91, 6);
CGPathAddLineToPoint(trianglePath, nil, 184, 222);
CGPathAddLineToPoint(trianglePath, nil, 2, 222);
CGPathAddLineToPoint(trianglePath, nil, 91, 6);

myNode.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:trianglePath];
// set rest of properties...

CGPathRelease(trianglePath);