2013-10-15 58 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); 語法不正確,但我知道你會弄明白 –