我想为我的 SpriteKit 游戏创建一个迷宫,但我在设置正确的物理体时遇到了问题。看看这个例子:
蓝色:CGPath
绿色:迷宫(CGPath 线宽=10)
红色:我要创建的物理体
我尝试用 CGPath 和 SKShapeNode 绘制迷宫,但如何为迷宫的内部边界设置物理体?
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 38, 266);
CGPathAddLineToPoint(path, NULL, 37, 23);
CGPathAddLineToPoint(path, NULL, 127, 22);
CGPathAddLineToPoint(path, NULL, 127, 184);
CGPathAddLineToPoint(path, NULL, 273, 185);
CGPathAddLineToPoint(path, NULL, 273, 98);
CGPathAddLineToPoint(path, NULL, 274, 184);
CGPathAddLineToPoint(path, NULL, 127, 184);
CGPathAddLineToPoint(path, NULL, 127, 23);
CGPathAddLineToPoint(path, NULL, 364, 23);
CGPathAddLineToPoint(path, NULL, 364, 266);
CGPathCloseSubpath(path);
SKShapeNode *labyrinth = [SKShapeNode shapeNodeWithPath:path];
labyrinth = [SKColor greenColor];
labyrinth.lineWidth = 10;
[self addChild:labyrinth];
.
labyrinth.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromPath:path];
不起作用。我需要一个选项来包括我的物理体路径的线宽。
对于实现这样的迷宫有什么建议或其他选择吗?
最佳答案
您是否考虑过用矩形 build 迷宫?
每个迷宫墙都可以是矩形或 Sprite 节点,然后您将使用 bodyWithRectangleOfSize:为每个形状/ Sprite 节点提供一个与其自身大小相同的物理体。
关于ios - 如何在 SpriteKit 中为带有物理体的迷宫创建路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31698615/