7

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.

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

Scroll to area of debugging overlay.

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.

Thanks in advance.

1

3 Answers 3

34

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.

1
  • 2
    This should be the correct answer, for iOS 8 aswell.
    – aramusss
    Mar 25, 2015 at 13:52
2

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];
2
  • Thanks, do you recommend the book was going to buy it last night. Nov 20, 2013 at 19:41
  • If you have done all the RW tutorials on his website and still want more then yes.
    – DogCoffee
    Nov 20, 2013 at 21:27
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.