Reputation: 1185
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.
Upvotes: 7
Views: 2998
Reputation: 1065
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.
Upvotes: 34
Reputation: 79
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];
}
Upvotes: 0
Reputation: 19946
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];
Upvotes: 2