Search code examples
libgdxtexturesgeometry

Drawing circles surrounding a texture using libgdx


I’m new in libgdx and I’m developing a simple game which consists in multiple items (fruits, balls, flowers, etc.) that are falling down through the screen. The goal is to fling them all to a certain position on the screen. These objects bounce on each other as well as on obstacles that are scattered on the screen. To program the physics involved in perform a bounce, I delimited each item with a "collision" circle. Since I'm new using libgdx, it was hard for me to put the circles in the correct position (over the texture of each item) and move them accordingly. Is there a way to debug that? I mean, is there a way to show each circle that surrounds each texture in order to corroborate if it is well positioned or not? I tried using ShapeRenderer and Pixmap unsuccessfully...any idea? Thks


Solution

  • This was my solution:

    game.batch.begin();
    // draw...
    game.batch.end();
    
    game.shapeRenderer.setProjectionMatrix(gameCam.combined);
    game.shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
    game.shapeRenderer.setColor(1, 1, 0, 1);
    
    // draw boundingRectangle's sprite: shapeRenderer.rect(getBoundingRectangle().x, getBoundingRectangle().y, getBoundingRectangle().width, getBoundingRectangle().height);
    
    game.shapeRenderer.end();