【问题标题】:Draw in color the shape of your SKPhysicsBody用颜色绘制 SKPhysicsBody 的形状
【发布时间】:2013-11-20 00:17:03
【问题描述】:

使用 SpriteKit 创建一个游戏,它实际上运行良好。我正在使用物理学并且能够看到我的身体的实际位置,因为我的精灵中可能有一些 alpha 真的很有帮助。这也将有助于创建更精确的实体。

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

滚动到调试覆盖区域。

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

提前致谢。

【问题讨论】:

标签: ios sprite-kit


【解决方案1】:

我相信您早就回答了您的问题,但从 iOS 7.1 开始,现在可以使用:

skView.showsPhysics = YES;

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

【讨论】:

  • 这应该是正确的答案,对于 iOS 8 也是如此。
【解决方案2】:

这是来自RW tutorial 的书。

- (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];

【讨论】:

  • 谢谢,你推荐这本书是昨晚要买的。
  • 如果你已经完成了他网站上的所有 RW 教程并且还想要更多,那么可以。
【解决方案3】:

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

用法:

import "YMCPhysicsDebugger.h"

- (void)createSceneContents {

  [YMCPhysicsDebugger init];

  // Create your nodes 

  [self drawPhysicsBodies];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-21
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    相关资源
    最近更新 更多