Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw SKNode PhysicsBody for debugging?

Tags:

ios

sprite-kit

I create my SKPhysicsBody with rectangle from size, I set it to size of the node, but the collision detection does not work on good portion of the node. How do I draw the red frame around physics body?

I tried using precise collision detection, but it doesn't help. I have checked some debug library but it draws only direct descendants of the scene, and my nodes are few levels deep. Author apparently doesn't know what recursion is.

How do I draw red frame around physics body if my body is rectangle?

like image 789
Dvole Avatar asked Mar 02 '14 11:03

Dvole


1 Answers

This works as of iOS 7.1 and in all OSX versions supporting SpriteKit.

In this example I'm using the variable mySKView to hold the SKView of the game.

Set the "showPhysics" property of your SKView to true/YES. This is usually done by adding the following line after the line "mySKView.showsFPS = true". Usually in the viewcontroller owning the SKView.

Obj-C:

mySKView.showsPhysics = YES;

Swift

mySKView.showsPhysics = true
like image 157
Theis Egeberg Avatar answered Nov 09 '22 08:11

Theis Egeberg