周三. 9月 27th, 2023

SpriteKit小工具

SpriteKit小工具 – SKPhysicsBody Path生成器

想要使用 [SKPhysicsBody bodyWithPolygonFromPath:path] 快速生成物理体路径嘛? 这个简单小工具能够帮助你实现,来试试吧!

步骤

  1. 把待绘制路径的图像拖动到下面的框中
  2. 点击图片上的位置开始绘制路径

规则 / 已知的问题:

  • 路径必须是具有逆时针缠绕且没有自相交的凸多边形路径(apple官方文档)
  • 为了避免兼容性请使用谷歌浏览器
视网膜显示器? (请在点选路径前选中)

X:0 Y:0


输出(OC)
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];