此函数将绘制房间的物理世界系统的表示,以帮助您在物理场景无法正常工作时进行调试。有时,问题可能出在游戏的渲染部分,例如,可能会在错误的位置或旋转处绘制精灵,从而导致物理效果不正确,或者可能是因为计算不正确。无论采用哪种方式,此函数都可以通过绘制物理系统中的内容来帮助您查找和解决问题。为此,您需要告诉它要绘制系统的哪个部分,这是通过传递从存储在各种"标志"常量中的位创建的值来完成的:
物理调试标志 | |
---|---|
Flag | 描述 |
phy_debug_render_aabb | This shows the absolute bounding box of each fixture in relation to the room axis |
phy_debug_render_collision_pairs | This will show any fixtures that are currently in collision |
phy_debug_render_coms | This marks the center of mass of each fixture in the room |
phy_debug_render_core_shapes | Shows the basic shapes that make up the fixtures in the room |
phy_debug_render_joints | This will draw each of the joints of all fixtures in the room |
phy_debug_render_obb | This shows the relative bounding box for the fixtures in the room |
phy_debug_render_shapes | This shows the actual shapes that make up fixtures within the room |
因此,要绘制这两个选项中的任意两个,我们需要对其中的两个选项执行位"或" (在 GameMaker中,这由 | 表示),并存储要使用的函数的结果变量。下面是一个如何设置变量的示例,该变量将与仅绘制房间中所有装置的重心和关节的函数一起使用:
flag = phy_debug_render_coms | phy_debug_render_shapes;
这会给你这样的结果:
正如您在上述代码中看到的,屏幕上只绘制了形状和重心(以及代表其状态的颜色-有关详细信息,请在线查看 Box 2D 文档)。以同样的方式,您可以显示更多甚至全部要调试的常量...只是"或者"他们都在一起!还需要注意的一点是,如果某个实例的绘制事件的深度低于要调试的实例的深度,则应仅调用此函数,否则将无法查看调试信息。
physics_world_draw_debug(flag)
参数 | 类型 | 描述 |
---|---|---|
flag | 物理调试标志(s) | 用于显示不同调试函数的标志值 |
N/A
flag = phy_debug_render_aabb | phy_debug_render_collision_pairs | phy_debug_render_obb;
physics_world_draw_debug(flag);
上面的代码将绘制当前物理系统中碰撞的所有绝对边界框、相对边界框以及装置。