Search code examples
libgdxshape-rendering

LibGDX shapeRenderer


I am developing my first game in LibGdx using scene2D.How can I render shapes for checking collision of different shaped entities?Currently I am rendering Rectangle and Circle shapes.But it does not looks proper for my requirements. Which is the best way to render shapes for checking collision?


Solution

  • If you're using scene2d you don't necessarily need to render some shapes using ShapeRenderer. scene2d provides you with a debug mode which will e.g. draw the set bounding boxes around an actor. This happens in drawDebug()

    Of course, you can override this method to add additional shapes (will use a ShapeRenderer inside). For example if you have an actor representing a ball, you might want to draw a circle around the border of the actor to see the clickable area in debug mode. Of course, you should then also override the collides() method accordingly to have correct collision detection.

    If you plan to do collision detection between different actors in your game, consider using box2D or have a look at the Intersector class.