Search code examples
colorslibgdxbox2dshapes

Adding color to lines Box2d (EdgeShape)


I'm making a game using libGdx and box2d tools.

I've been using EdgeShape class to draw lines in Box2d which I will later add collision detector. I know how to add Textures to Fixtures etc., but could I somehow add colors to edges drawn with EdgeShape? Or am I forced to instead of lines draw rectangles?


Solution

  • Box2D does not provide any graphical assistance whatsoever. It is meant as the backend for a game. You get the position of your bodies and then use something such as SpriteBatch or ShapeRenderer to draw the appropriate sprite or shape to represent that body in your game.

    If you are simply debugging your game and want to see all the bodies involved, you can use Box2DRenderer which will display them in very simple terms. Please note that this is not meant for use in the final release of a product and it will give you a significant performance hit if you do choose to include it.

    To draw 2D in Libgdx.

    To use Box2DRenderer in Libgdx.