Search code examples
javalibgdxbox2d

Make body borders invisible/different color


Java LibGdx Box2d

I would like to make body borders invisible or at least different color. One body should work as sensor and thus not be visible on the screen. I could not find a valid answer for that in hours and I cannot believe there is no such option in this library so I assume I must have missed one liner somewhere in Docs.

I would like to make this square transparent/invisible or at least different color but still keep it to discover movement of these circles.

enter image description here

Looking over stackoverflow and googling it in docs.

Closest things I found: Make invisible body line box2d libgdx

so maybe the only solution to this is setting some flags in render method or unique render methods for each body?


Solution

  • What I can see on your screenshot is Box2d's shapes for debugging.

    They were not designed to have adjustable visuals and are here only to show you the precise shapes and positions of your Box2d's entities.

    According to the wiki (https://libgdx.com/wiki/extensions/physics/box2d#debug-renderer):

    Debug Renderer

    The next thing we are going to do is setup our debug renderer. You generally will not use this in a released version of your game, but for testing purposes we will set it up now like so: ...

    You will need some other kind of renderer if you want to adjust the visuals. For example:

    Retrieve the positions / shapes / sizes of your Box2d entities and use one of the more advanced renderers to draw shapes or textures in positions of your Box2d entities. Box2d is not designed for drawing stuff, it just simmulates the physics and gives you position / rotation of bodies and some other info about its world.