using self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:

163 Views Asked by At

I want to use

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

in spriteKit but I am not sure how to go about it. I have googled how to create paths but couldn't find much Then when I have made a UIBezierPath I can't figure out how to change it to a CGPath and then use that in the about. I want to use these point to create a path (91,6),(184,222),(2,222) and then back to (91,6) to make a triangle. Can someone help me.

1

There are 1 best solutions below

0
On BEST ANSWER

Here is an example for creating a physics body using a path:

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);