Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

libgdx: SpriteBatch and ShapeRenderer projection wrong

$
0
0

I’m using LibGDX and the SpriteBatch and ShapeRenderer are having a perspective problem or something… When I draw something with both (code below), the planet texture is smaller than it should be. I can even manually set the size values and it’s still wrong.

I’m setting:

    Matrix4 matrix = cam.combined;
    batch.setProjectionMatrix(matrix);
    sr.setProjectionMatrix(matrix);

and the draw code is…

            // outline
            sr.begin(ShapeRenderer.ShapeType.Filled);
            sr.setColor(Color.BLACK);
            sr.circle(c.getPos().x,c.getPos().y,c.getSize());
            sr.end();

            // planet tex
            batch.begin();
            batch.draw(c.getTexture(), c.getDrawPosition().x, c.getDrawPosition().y, c.getSize(), c.getSize());
            batch.draw(c.getShadow(), c.getDrawPosition().x, c.getDrawPosition().y, c.getSize(), c.getSize());
            batch.end();

Both the texture and the shape are centered properly and c.getSize() should always be returning the same value, so I’m trying to figure out why this isn’t working. I’ve tried manually setting the value for size and it still does it, so either the texture is being rendered at the wrong size or somehow the ShapeRenderer and SpriteBatch are using a different camera/projection.


Viewing all articles
Browse latest Browse all 434

Trending Articles