1
\$\begingroup\$

I extended the SuperKoalio LibGDX Example about an Tiled Object Layer in the Tiled Level-Editor and draw a rectangle on this layer. Now I would like to draw this rectangle in my game using the ShapeRenderer debugRenderer from the above SuperKoalio Example.

So, I changed the renderDebug method from example:

private void renderDebug () {
    Gdx.graphics.getGL20().glLineWidth(1.5F);

    // I think something is wrong with this:
    debugRenderer.setProjectionMatrix(camera.combined);

    debugRenderer.begin(ShapeType.Line);

    //Removed the rendering of the rectangles around ground and player

    // I added the object layer "objects" in the level1.tmx map
    // And this code:
    MapLayer objectLayer = map.getLayers().get("objects");
    debugRenderer.setColor(Color.RED);
    Rectangle rect;     
    for(MapObject mo : objectLayer.getObjects()) {
        rect = ((RectangleMapObject) mo).getRectangle();
        debugRenderer.rect(rect.x, rect.y, rect.width, rect.height);
    }

    debugRenderer.end();
}

Running this looks like: Rectangle in tiled but not visible in game The rectangle is missing in game and I can't figure out why. Removing the setting of the ProjectionMatrix camera.combined makes the rectangle visible but it doesn't stick on the map and scrolls with the player. The position is a little wrong, too.

You can find my gist with modified example here.

How do I render this rectangle correctly? Thanks in advance!

\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.