2013-04-14 32 views
0

我一直在使用slickutils在LWJGL中嘗試字符串打印。通常瀏覽網頁時,我發現了兩種方法。首先是位圖,你有一個完整的字母表,並打印每個字母作爲紋理,另一個使用TrueTypeFont s和truetypefont.drawString(20f,20f,"LWJGL String Test", Color.green)方法。 然而,我發現的大多數文獻都是幾歲。目前正確的做法是什麼?使用slick2d和TTF繪製字符串

目前我正在使用TrueTypeFont方法,但是我的結果令我困惑。 enter image description here

//It doesn't matter which Font I try to load, I get the same green bar. 
//I think it has something to do with not finding the Fonts? 
Font awtFont = new Font("Times New Roman", Font.BOLD, 24); 
TrueTypeFont font = new TrueTypeFont(awtFont, true); 
font.drawString(20f, 20f, "LWJGL TEST STRING",Color.green); 

我也是從網上抄的例子,並得到相同的結果(只是一個欄)。 嘗試使用谷歌搜索,但無法找到任何修復。

回答

0

TrueTypeFont已棄用。改用UnicodeFont。

檢查:

// Create a font with the size of 20, and not bold or italic. 
Unicode font = new UnicodeFont("res/font.ttf", 20, false, false); 

font.addAsciiGlyphs(); 
font.getEffects().add(new ColorEffect()); 
font.loadGlyphs(); 

g.setFont(font); 
g.drawString("Shit example", 100, 100); 
+0

嗯,從谷歌上搜索更多的,似乎我應該使用'BitmapFont'雖然我無法找到任何教程。你碰巧知道這件事嗎? –

+0

位圖字體是由圖像文件分割而成的。這我就是我所知道的。哦,我的世界也使用了Bitmap字體。 :) – HUNeater

+0

哦,經過一番搜索,我明白了。在Slick2d中,這被稱爲AngelCodeFont。 ''字體=新的AngelCodeFont(「res/demo.fnt」,「res/demo.tga」);' [更多信息](http://www.slick2d.org/wiki/index.php/AngelCodeFont) – HUNeater