Not sure if this helps someone or not, but I was able to correctly process the textures and fonts using the proposed inverted coordinate system through OrthographicCamera. Here is what I did:
private SpriteBatch batch; private BitmapFont font; private OrthographicCamera cam; private Texture tex; @Override public void create () { batch = new SpriteBatch(); font = new BitmapFont(true); font.setColor(Color.WHITE); cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); tex = new Texture("badlogic.jpg"); } @Override public void dispose() { batch.dispose(); font.dispose(); tex.dispose(); } @Override public void render () { cam.update(); batch.setProjectionMatrix(cam.combined); Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); font.draw(batch, "Test", 50, 50); batch.draw(tex, 100, 100, tex.getWidth(), tex.getHeight(), 0, 0, tex.getWidth(), tex.getHeight(), false, true); batch.end(); }
It is important to note:
- BitmapFont constructor, boolean flips the font
- For batch.draw (), you need to use all these parameters because you need the boolean flipY at the end to flip the texture (I can extend SpriteBatch or make a utility method so as not to skip so many parameters all the time.)
- Check out the batch.setProjectionMatrix package (cam.combined); in render ()
Now we will see if I come back here later, will make changes to fix any other problems or discoveries by doing all this. :)
User 04 Oct '15 at 18:33 2015-10-04 18:33
source share