0
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

It looks like you want to draw the circle with half the c.size () as the circle method's third parameter is radius, not diameter.

sr.circle(c.getPos().x,c.getPos().y,c.getSize() / 2.0f);

Either that or multiply the width and height passed in the draw calls for the textures by two.

The draw calls on the SpriteBatch takes width and height and the width of a circle is two times the radius.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.