用彩色绘制SKPhysicsBody的形状 [英] Draw in color the shape of your SKPhysicsBody

查看:107
本文介绍了用彩色绘制SKPhysicsBody的形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Creating a game with SpriteKit and its actually working out very well. I am using physics and having the ability to see actually where my bodies are because I might have some alpha inside of my sprites will really be helpful. This will also be helpful for creating more precise bodies.

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

In the documentation for SpriteKit they talk about a debugOverlay but the only example they give is to draw the direction of gravity. Here is the link: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html

滚动到调试覆盖区域。

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

Has anybody written some code that can easily access the body of all objects in a scene and draw the exact size of them and place them where they should be in the correlation? I'm very surprised apple did not just add some type of DrawGizmos property to the physics body.

提前致谢。

推荐答案

这是来自 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]; 
  }

要在节点上使用此功能,

To use this on a node,

 [mySpriteToDebug attachDebugRectWithSize:contactSize];

这篇关于用彩色绘制SKPhysicsBody的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆