ios – 以您的SKPhysicsBody的形状绘制颜色

前端之家收集整理的这篇文章主要介绍了ios – 以您的SKPhysicsBody的形状绘制颜色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用SpriteKit创建游戏并且它实际上运行得非常好.我正在使用物理学并且有能力实际看到我的身体在哪里,因为我可能在我的精灵中有一些alpha会真的很有帮助.这对于创建更精确的实体也很有帮助.

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

滚动到调试覆盖区域.

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

提前致谢.

解决方法

这是从 RW tutorial书.
  1. - (void)attachDebugRectWithSize:(CGSize)s {
  2. CGPathRef bodyPath = CGPathCreateWithRect( CGRectMake(-s.width/2,-s.height/2,s.width,s.height),nil);
  3. [self attachDebugFrameFromPath:bodyPath];
  4. CGPathRelease(bodyPath);
  5. }
  6.  
  7. - (void)attachDebugFrameFromPath:(CGPathRef)bodyPath {
  8. //if (kDebugDraw==NO) return;
  9. SKShapeNode *shape = [SKShapeNode node];
  10. shape.path = bodyPath;
  11. shape.strokeColor = [SKColor colorWithRed:1.0 green:0 blue:0 alpha:0.5];
  12. shape.lineWidth = 1.0;
  13. [self addChild:shape];
  14. }

要在节点上使用它,

  1. [mySpriteToDebug attachDebugRectWithSize:contactSize];

猜你在找的iOS相关文章