How can I draw text (font) on top of my static box2d body?
Background: Im able to draw sprites on top of bodies correctly.
I do this by having a box2dSpriteBatch
which is projected on box2dCamera like so box2dSpriteBatch.setProjectionMatrix(box2dCamera.combined);
And then simply rendering the sprite in the correct spot using getPosition
of the body.
But if i try the same way for fonts, unfortunately it scales incredibly large, and if i try to scale the font down it doesn't appear. So im assuming I need to draw the text in window coordinates instead of box2d.
My attempt:
in show():
windowCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
in my Render method i call
windowSpriteBatch.setProjectionMatrix(windowCamera.combined);
also in Render i render the font
whiteFont.setScale(0.7f, 0.7f); sb.begin(); whiteFont.draw(sb, "2", body.getPosition().x, (questionLineBody.getPosition().y)*PPM); sb.end();