I wonder if there is a tool that could be used for easy generation of complex physics bodies in SpriteKit. I would like to have a volume based physical bodies with polygon-t
I am looking for the exact same thing, as it turn out I have done a small web app for this purpose.
SKPhysicsBody Path Generator
as action in example:
Update 2015-02-13: script
SpriteKit Tools - SKPhysicsBody Path Generator
SKPhysicsBody Path Generator
Want to use [SKPhysicsBody bodyWithPolygonFromPath:path] easier way like me? Here with a small helper for easier path drawing, hope it help others too.
Basic Instruction
- Drag and drop the sprite image into drop zone.
- Start drawing path by clicking on coordinates.
Some Rules / Known Issue
- Path need to be as a convex polygonal path with counterclockwise winding and no self intersections. The points are specified relative to the owning node’s origin. (documentation link)
- Please use Chrome for best compatibility as I have not tested on other browsers.
Retina? (please check before declaring path)
X:0 Y:0
Output
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"img"];
CGFloat offsetX = sprite.frame.size.width * sprite.anchorPoint.x;
CGFloat offsetY = sprite.frame.size.height * sprite.anchorPoint.y;
CGMutablePathRef path = CGPathCreateMutable();
CGPathCloseSubpath(path);
sprite.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];