SpriteKit's SKPhysicsBody with polygon helper tool

前端 未结 8 2221
面向向阳花
面向向阳花 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:26

    You can just do this now to generate physics body from your sprite's PNG:

    SKSpriteNode *yourPhysicsSprite = [SKSpriteNode spriteNodeWithImageNamed:@"yourPNG"];
    yourPhysicsSprite.physicsBody = [SKPhysicsBody bodyWithTexture:yourPhysicsSprite.texture alphaThreshold:0.0f size:yourPhysicsSprite.texture.size];
    

    Less precise and perhaps more costly than doing by hand, but works fine.

提交回复
热议问题