OGEngine教程:字体工具使用

1.打开 BitmapFont tool,在红框中输入你要显示的字。

2.写完后保存字体文件

保存后能够得到一个.fnt  和  一个.png 文件

3.使用 TexturePacker 工具将bitmapFont.png转换pvr格式通过Add Sprites把 bitmapFont.png导入,填写好相关文件保存位置和名字。


注意以下红框部分的參数设置,跟以下的截图调成一样...

点击  Publish  就会生成三个文件,当中 bitmapFont.java 不需用到。

我们把当中的  bitmapFont.pvr.cczbitmapFont.xmlbitmapFont.fnt 复制到安卓project的

assets/font 文件夹下:

4.经过上面的步骤资源已经准备完成,以下转入代码实现。注意所输入的字必须是之前制作所包括的字,否则无法显示,对于英文来说就是 26 个字母就全了。可是中文就要依据须要制作了。

// 字体 

BitmapFont bitmapFont = new BitmapFont(this.getEngine().getTextureManager(),Device.getDevice().getFileManage(),"font/bitmapFont.fnt");

bitmapFont.load();

Text bitmapText = new Text(50, 230, bitmapFont, "Hello World!",  

new TextOptions(HorizontalAlign.CENTER), this.getVertexBufferObjectManager()); 

this.attachChild(bitmapText); 

Text bitmapText2 = new Text(50, 300, bitmapFont, "世界你好!", 

       new TextOptions(HorizontalAlign.CENTER), this.getVertexBufferObjectManager()); 

this.attachChild(bitmapText2);

原文地址:https://www.cnblogs.com/lxjshuju/p/6843859.html