1

I want to draw some fonts in my game (in libgdx). I have no errors, everything works but I don't see fonts. I don't know why. Maybe someone had the same problem. Thanks for help. Here is my code in create method:

String scores = "SCORE:";
atlas = new TextureAtlas();
    camera = new OrthographicCamera(1, h/w);
    batch = new SpriteBatch();
    score = new BitmapFont(Gdx.files.internal("gfx/abc.fnt"),
            atlas.findRegion("gfx/abc.png"), false);

and render:

Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    camera.update();
    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    score.draw(batch, scores, 300, 300);
    Gdx.app.log("", ""+scores);
    batch.end();
user978758
  • 609
  • 3
  • 17
  • 29

1 Answers1

1

Ok I solved the problem. I added the code in render method:

batch.setProjectionMatrix(new Matrix4().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
user978758
  • 609
  • 3
  • 17
  • 29
  • now you generate a new object inside of your render that shouldnt be good. Create the Matrix4 as atribut of the class and just set the ortho. – bemeyer Oct 15 '13 at 15:39
  • BennX is right. Another solution to ur problem is to set the size of your font in ratio to your viewport ratio. Something like font.setsize(size.x/40,size.y/40); syntax is not proper but i know u will figure it out – Kumar Saurabh Oct 16 '13 at 09:48
  • I have the same issue, I am stumped. I call the draw method on font in one class derived from X and it works fine, I call it in another class that is also derived of X and it doesn't display anything... I don't know what I am doing wrong. – AgentM Oct 30 '18 at 00:11