2016-07-28 114 views
1

好的我一直在尋找這麼久,而且我似乎找不到解決我的問題的好方法。我知道libgdx中的TextArea類用於用戶輸入。人們使用它,以便用戶可以輸入多行字符串。我需要類似於TextArea的東西,而這恰恰相反。我想在特定區域向用戶顯示文字(就像文本區域一樣),但我希望它在我遊戲中的某種窗口中(有點像表格或對話框,而不會提示用戶輸入輸入)。誰能幫我這個?或者這是我必須從頭開始做的事情?Libgdx如何顯示文字?

+1

在您的廣泛搜索,我想你忘了看看LibGDX文檔。 :) https://github.com/libgdx/libgdx/wiki/Scene2d.ui#label https://github.com/libgdx/libgdx/wiki/Bitmap-fonts – Tenfour04

+0

標籤不會做我想要的 –

+0

另外我瞭解位圖字體。我很好,使用位圖字體。我只需要一個容器來放我的文字。一個標籤是醜陋的,當我需要它打印一條新線時,它會向前移動上一個文本。我需要一個容器,它將在必要時在上一行下打印一個新行。這很像TextArea,但它用於輸出而不是輸入 –

回答

0

使用gdxVersion = '1.4.1'(Android Studio中的gradle與建),該代碼繪製文本成功:

BitmapFont font = new BitmapFont(); //or use alex answer to use custom font 

public void render(float dt) 
    { 
    batch.setProjectionMatrix(camera.combined); //or your matrix to draw GAME WORLD, not UI 

    batch.begin(); 
    //draw background, objects, etc. 
    for(View view: views) 
    { 
     view.draw(batch, dt); 
    } 

    font.draw(batch, "Hello World!", 10, 10); 
    batch.end(); 
    } 

幸得@Deepscorn

欲瞭解更多你可以通過這個教程:

  1. Libgdx tutorial for simply display the words Hello World on screen.
  2. How can I draw text using Libgdx/Java?
  3. libGDX - Add scores & display it at top left corner of the screen?
+0

不完全。我喜歡關於文本區域的東西是我可以給它一種圖像屬性,這樣我就可以在屏幕上繪製一個圖像,並在其中包含一些文本。我需要這樣做,但沒有它,所以需要投入。相反,它只是向用戶輸出文本 –

0

您可以使用Label類,並在LabelStyle設置背景繪製:

Label.LabelStyle style = new LabelStyle(); 
style.background = ...; // Set the drawable you want to use 

Label label = new Label("Text here", style);