简体   繁体   English

Slick2D 字体不起作用

[英]Slick2D Fonts don't work

I have Slick2D library and making a game in Java.我有 Slick2D 库并用 Java 制作游戏。 I have been wondering, just a short question, how do you set fonts on Graphics object to draw in a different font.我一直想知道,只是一个简短的问题,您如何在 Graphics 对象上设置字体以使用不同的字体进行绘制。 I can't make it work.我不能让它工作。 I think it has something to do with AngelCode but that requires some format that isn't '.tff' so I don't know.我认为它与 AngelCode 有关,但这需要某种不是“.tff”的格式,所以我不知道。

So can you tell me how you do it?那你能告诉我你是怎么做到的吗?

You can use angel code's BMF font tool, which makes bitmap font files with a glyph image that stores the character images, and a text file that describes the image file (windows only, Herio.jar is similar and is included with slick, but it only works sometimes, crashing on me repeatedly)您可以使用angel code的BMF字体工具,该工具使用存储字符图像的字形图像和描述图像文件的文本文件制作位图字体文件(仅限Windows,Herio.jar类似并包含在slick中,但它仅有时有效,反复撞到我)

  1. Get BMF font here and install it with the included windows installer.在此处获取 BMF 字体并使用随附的 Windows 安装程序进行安装。 Once you have done that, use the GUI to select a font, size, etc. (note that you have to make 1 font/glyh image pair per size and font) Then highlight the boxes that contain characters you want to use, noting that slick only supports up to 256 (I think) characters.完成后,使用 GUI 选择字体、大小等(请注意,您必须为每个大小和字体制作 1 个字体/glyh 图像对)然后突出显示包含要使用的字符的框,注意slick 最多只支持 256 个(我认为)字符。

  2. you need to Change some export settings so that slick will recognize the files.您需要更改一些导出设置,以便 slick 识别文件。 Go to file -> export options and change the the "bit channels" (I think that's what its called) A -> glyph R,G, and B -> one.转到文件 -> 导出选项并更改“位通道”(我认为这就是它的名称)A -> 字形 R、G 和 B -> 一。 Set presets to custom, and the textures to .png files, and your configuring is done.将预设设置为自定义,将纹理设置为 .png 文件,您的配置就完成了。

  3. Export your newly created font files [file -> save bitmap font as] (yes, it will make a glyph image (.png), and a text descriptor file with the extension .fnt) in your appropriate data directory.导出新创建的字体文件 [文件 -> 将位图字体另存为](是的,它将在适当的数据目录中生成字形图像 (.png) 和扩展名为 .fnt 的文本描述符文件)。

  4. Code it in by using the AngelCodeFont constrcutor:使用 AngelCodeFont 构造器对其进行编码:

    fnt = new AngelCodeFont("LOCATION OF .fnt FILE", new Image("LOCATION OF .png GLYPH IMAGE");

then you can then either draw with it directly:然后你可以直接用它绘制:

fnt.drawString(float x, float y, "TEXT TO DISPAY");

or you can或者你可以

set the current graphics font as the AngelCodeFont and draw directly through the graphics class.将当前图形字体设置为AngelCodeFont,直接通过图形类进行绘制。

GraphicsObject.setFont(fnt);
GraphicsObject.drawString("THIS WLL DRAW IN THE ANGEL CODE FONT");

hope this helped :D希望这有帮助:D

more info here, in the API documentation: http://slick.cokeandcode.com/javadoc/ API 文档中的更多信息: http : //slick.cokeandcode.com/javadoc/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM