是否可以为 body 创建一个可能被其他 body 破坏的夹具?

is it possible to create a fixture for a body that could be broken by some other body?

我真的很想知道,是否可以为 body 创建一个可以被其他 body 破坏的夹具?

有例子:

P.s。是否有任何程序可以帮助创建 such fixture?

是的,您可以使用 Breakable 发现于:

net.dermetfan.gdx.physics.box2d.Breakable

Breakable 允许轻松地使整个物体或单个固定装置易碎,这意味着如果对它们施加一定的力或摩擦,它们就会被破坏。

使用方法

A Breakable is meant to be put in a body's, fixture's or joint's user data. A single Breakable instance can be put in the user data of multiple bodies, fixtures and joints. Since this may collide with the Box2DSprite or other classes using the user data, the Breakable$Manager uses a Function to access the Breakable in the user data of a body, fixture or joint.Do not forget to set a Manager instance as ContactListener to the world and to call destroy() after every timestep. If the field is already in use, check out the ContactMultiplexer. The Manager does the actual work, the Breakables are just passive data holders.

A Breakable consists of a normal resistance, tangent resistance, an option to destroy its body in case its last fixture was destroyed and an option setting if the body should be destroyed no matter the amount of remaining fixtures.

The normalResistance is the force that can be applied to the Breakable before it breaks (inclusive). The tangentResistance is the friction the Breakable can bear (also inclusive). The reactionForceRestiance specifies the reaction force a joint can bear on each axis. The reactionForceLength2Resistance is the max squared length of the joint's reaction force the Breakable can bear.

参考libgdx-utils

其他一些很好的参考资料和很好的例子here and here

for the question (Are there any programs that could help the process of creating such fixture)

是的,你可以轻松使用 box2d-editor,它允许你创建复杂的多边形,你还可以从你的图像或精灵创建你的身体和形状查看官方文档在同一页面中有几个视频解释了 box2d-editor 的工作方式:

特点:

  • Automatically decomposes concave shapes into convex polygons,
  • Automatically traces your images if needed,
  • Supports multiple outlines for a single body,
  • Supports polygon and circle shapes,
  • Reference point location can be changed,
  • Visual configurable grid with snap-to-grid option,
  • Built-in collision tester! Throw balls at your body to test it,
  • Loader provided for LibGDX game framework (written in Java),
  • Simple export format (JSON), to let you easily create your own loader for any framework in any language.