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
This is an adaptation of Xelt's answer in Swift 3.
SpriteKit Tools - SKPhysicsBody Path Generator (Swift version
SKPhysicsBody Path Generator
Want to use SKPhysicsBody(polygonFromPath: 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
let sprite = SKSpriteNode(imageNamed: "codeImgName")
let offsetX = sprite.size.width * sprite.anchorPoint.x
let offsetY = sprite.size.height * sprite.anchorPoint.y
let path = CGMutablePath()
path.closeSubpath()
sprite.physicsBody = SKPhysicsBody(polygonFromPath: path)