Search code examples
javaslick2djbox2d

How to use JBox2D debug-draw in Slick2D?


JBox2D, the Java port of the Box2D physics engine, features an extensible module for creating debug drawing of shapes. How can I use this with the Slick2D game library?


Solution

  • Using the JBox2D DebugDraw class for Slick2D it is simple to add debug drawing. Put the below code in your init method:

    Slick2DJBox2DDebugDraw debugDraw = new Slick2DJBox2DDebugDraw(gameContainer);
    debugDraw.setFlags(DebugDraw.e_shapeBit);
    world.setDebugDraw(debugDraw); // Where world is your JBox2D world