Draw in color the shape of your SKPhysicsBody

时光怂恿深爱的人放手 提交于 2019-12-05 04:47:35

This is from RW tutorial book.

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

I'm sure you've long since answered your question, but as of iOS 7.1 it is now possible to use:

skView.showsPhysics = YES;

Which works much better than the YMCPhysicsDebugger. YMCPhysicsDebugger is also no longer supported.

You can use a library by ymc-thzi.
https://github.com/ymc-thzi/PhysicsDebugger

Usage:

import "YMCPhysicsDebugger.h"

- (void)createSceneContents {

  [YMCPhysicsDebugger init];

  // Create your nodes 

  [self drawPhysicsBodies];
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!