egret.BitmapText 使用範例, 關於點陣文字生成請參考 egret.BitmapFont
class Main extends eui.UILayer {
protected createChildren(): void {
super.createChildren();
egret.lifecycle.onPause = () => egret.ticker.pause();
egret.lifecycle.onResume = () => egret.ticker.resume();
egret.registerImplementation('eui.IAssetAdapter', new AssetAdapter());
egret.registerImplementation('eui.IThemeAdapter', new ThemeAdapter());
this.runGame();
}
private async loadResource() {
let loadingView = this.stage.addChild(new LoadingUI()) as LoadingUI;
await RES.loadConfig('resource/default.res.json', 'resource/');
await new Promise(resolve => new eui.Theme('resource/default.thm.json', this.stage).once(eui.UIEvent.COMPLETE, resolve, this));
await RES.loadGroup('preload', 0, loadingView);
this.stage.removeChild(loadingView);
}
private async runGame() {
await this.loadResource();
// --- Edwin 給你最乾淨的程式碼, 從這行以下開始寫喔 ---
const bt = new egret.BitmapText(); // 建立 BitmapText 物件用於顯示 BitmapFont
bt.font = RES.getRes('myFont_fnt'); // 這個資源即為 BitmapFont
bt.text = '0123456789';
this.addChild(bt);
// 建議用 eui.BitmapLabel 取代 egret.BitmapText, 使用上方便些
const bl = new eui.BitmapLabel('99');
bl.font = 'myFont_fnt'; // 直接給予指定資源的索引名即可
bl.y = 500;
this.addChild(bl);
}
}
沒有留言:
張貼留言