How to draw SKNode PhysicsBody for debugging?

寵の児 提交于 2019-12-10 03:28:48

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/22127221/how-to-draw-sknode-physicsbody-for-debugging

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