I really want to know, is it possible to create a fixture for a body that could be broken by some other body?
There is the example:
- a body with its fixture divided into small figures:
- and what happens after it is hit by another body:
P.s. Are there any programs that could help the process of creating such fixture?
Best How To :
yes you can do this bye using
Breakable spotted at :
The Breakable allows to easily make whole bodies or single fixtures breakable, which means they will be destroyed if a certain force or friction is applied to them.
How to use
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.
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.
referred to libgdx-utils
some other good references with good examples here and here
for the question
(Are there any programs that could help the process of creating such fixture)
yes you can easily use box2d-editor which allows you to create complex polygons and you can also create your bodies and shapes from your images or sprites check the official documentation in the same page there are several video who explain the way box2d-editor works :
- 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.