2013-10-15 60 views
1

我想在我的游戏中绘制一些字体(在libgdx中)。我没有错误,一切正常,但我没有看到字体。我不知道为什么。也许有人有同样的问题。感谢帮助。 这里是我的代码 在创建方法:不会在libgdx中绘制字体

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); 

和渲染:

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(); 

回答

0

好吧,我解决了这个问题。我在渲染方法中添加了代码:

batch.setProjectionMatrix(new Matrix4().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); 
+0

现在,您在渲染器内部生成了一个不错的新对象。创建Matrix4作为该类的一个分类,并设置正交。 – BennX

+0

BennX是对的。你的问题的另一个解决方案是设置你的字体的大小与你的视口比例的比例。 类似font.setsize(size.x/40,size.y/40); 语法不正确,但我知道你会弄明白 –