Search code examples
javaandroidlibgdxcollision

Color Libgdx Rectangle object


I'm making collisions for my game using libgdx and I'm having some issues. Things don't fall right. I'm using Rectangle objects around my character and terrain and would like to know if there is any way to color/show the rectangle so I can see exactly why are collisions are buggy. Is this possible?

These are the rectangles :

private Rectangle bottom, left, right, top, full;

 full = new Rectangle(0f,0f,128f,10f);
        bottom = new Rectangle(0f,0f,128f,16f);
        left = new Rectangle(0f,16f,64f, 96f);
        right = new Rectangle(64f,16f,64f,96f);
        top = new Rectangle(0f,112f,128f,16);

Solution

  • You will need to use ShapeRenderer

    https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html

    ShapeRenderer shapeRenderer;
    shapeRenderer = new ShapeRenderer();
    shapeRenderer.begin(ShapeType.Line);
    shapeRenderer.rect(x, y, width, height);
    shapeRenderer.end();