0
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ Your title asks for scaling, your question asks for centralization. What are you really asking here? What do you want to fix? \$\endgroup\$ – Gustavo Maciel Jun 2 '15 at 11:56
1
\$\begingroup\$

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((Gdx.graphics.getWidth() - sprite.getWidth())/2 ,(Gdx.graphics.getWidth() - sprite.getheight())/2 );

or even:

batch.draw(texture, (Gdx.graphics.getWidth() - texture.getWidth())/2 ,(Gdx.graphics.getWidth() - texture.getheight())/2);
\$\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.