SpriteKit's SKPhysicsBody with polygon helper tool

前端 未结 8 2187
面向向阳花
面向向阳花 2020-11-28 21:45

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

8条回答
  •  清酒与你
    2020-11-28 22:48

    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: enter image description here

    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
    1. Drag and drop the sprite image into drop zone.
    2. 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];
    

提交回复
热议问题