7
\$\begingroup\$

Currently, I'm able to scale the screen by applying this bit of code onto an OrthographicCamera

Camera.setToOrtho(true, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

But something quite strange is happening with this solution, take a look at this picture of my game below

picture

Seems fine right? But upon further investigation, many components are rendered off by one pixels, and the tiles all are.

Take a closer look

picture

I circled a couple of the errors. Note that the shadow of the warrior I circled appears fine for the other warriors. Also keep in mind that everything is rendered at pixel-perfect precision when I disable the scaling.

I actually thought of a possible source for the problem as I'm writing this but I decided to still post this because I would assume somebody else might run into the same issue.

\$\endgroup\$
7
\$\begingroup\$

It turns out my initial suspicions were right. The SpriteBatch draw method takes floats for the X and Y, so I decided to feed it my positions as is, kept as floats. WRONG. It seems that the SpriteBatch class can't round properly or something because when I cast all of the values to integers and then gave it that, everything turned back to normal and is rendering like it should.

\$\endgroup\$
  • \$\begingroup\$ Please mark this as the accepted answer (after two days or whatever the minimum is). \$\endgroup\$ – ashes999 Oct 24 '13 at 0:51
  • \$\begingroup\$ Yeah I wanted to mark it but turns out I can't for 2 days and I don't know why \$\endgroup\$ – oxysoft Oct 24 '13 at 0:56
  • \$\begingroup\$ It's to prevent people just asking/answering their own questions immediately for rep. Please come back and accept it after two days :) \$\endgroup\$ – ashes999 Oct 24 '13 at 2:26
  • \$\begingroup\$ I'm pretty sure you don't get rep for answering your own question... \$\endgroup\$ – rodrigo-silveira Dec 22 '13 at 7:51

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.