1.打開 BitmapFont tool,在紅框中輸入你要顯示的字。
2.寫完後保存字體文件
保存後可以得到一個.fnt 和 一個.png 文件
3.使用 TexturePacker 工具將bitmapFont.png轉換pvr格式通過Add Sprites把 bitmapFont.png導入,填寫好相關文件保存位置和名字。
注意下面紅框部分的參數設置,跟下面的截圖調成一樣...
點擊 Publish 就會生成三個文件,其中 bitmapFont.java 不需用到。
我們把其中的 bitmapFont.pvr.ccz、bitmapFont.xml、bitmapFont.fnt 拷貝到安卓工程的
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);