用彩色绘制SKPhysicsBody的形状

使用SpriteKit创建游戏并且它实际上运行得非常好。 我正在使用物理学并且有能力实际看到我的身体在哪里,因为我可能在我的精灵中有一些alpha会真的很有帮助。 这对于创建更精确的实体也很有帮助。

在SpriteKit的文档中,他们讨论了debugOverlay,但他们给出的唯一例子是绘制引力方向。 这是链接: https : //developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html

滚动到调试覆盖区域。

是否有人编写了一些代码,可以轻松访问场景中所有对象的主体并绘制它们的确切大小并将它们放在相关的位置? 我很惊讶苹果不仅仅在物理机构中添加了某种类型的DrawGizmos属性。

提前致谢。

这是来自RW教程书。

- (void)attachDebugRectWithSize:(CGSize)s { CGPathRef bodyPath = CGPathCreateWithRect( CGRectMake(-s.width/2, -s.height/2, s.width, s.height),nil); [self attachDebugFrameFromPath:bodyPath]; CGPathRelease(bodyPath); } - (void)attachDebugFrameFromPath:(CGPathRef)bodyPath { //if (kDebugDraw==NO) return; SKShapeNode *shape = [SKShapeNode node]; shape.path = bodyPath; shape.strokeColor = [SKColor colorWithRed:1.0 green:0 blue:0 alpha:0.5]; shape.lineWidth = 1.0; [self addChild:shape]; } 

要在节点上使用它,

  [mySpriteToDebug attachDebugRectWithSize:contactSize]; 

我确定你早就回答了你的问题,但是从iOS 7.1开始,现在可以使用:

skView.showsPhysics = YES;

哪个比YMCPhysicsDebugger好得多。 YMCPhysicsDebugger也不再受支持。

您可以使用ymc-thzi的库。
https://github.com/ymc-thzi/PhysicsDebugger

用法:

 import "YMCPhysicsDebugger.h" - (void)createSceneContents { [YMCPhysicsDebugger init]; // Create your nodes [self drawPhysicsBodies]; }