LibGdx Scalling sprites on Android

| | August 4, 2015

I have a sprite that is a few buttons but need them in the center of the screen for all android devices. I tried setting it’s location to the center of the screen by dividing the orthogonal camera by 2, but it doesn’t help. Any simple way to fix this?

One Response to “LibGdx Scalling sprites on Android”

  1. If you want to draw the sprite in the exact center, you have to take the sprite’s height and width into account. Assuming your viewport’s width and height are set equal to the device’s width and height. You can set the sprite’s position this way

    sprite.setPosition(( - sprite.getWidth())/2 ,( - sprite.getheight())/2 );

    or even:

    batch.draw(texture, ( - texture.getWidth())/2 ,( - texture.getheight())/2);

Leave a Reply