egret.HtmlTextParser 使用範例
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 label = new eui.Label; // eui.Label 可以取代 egret.TextField
label.width = 480;
label.textAlign = egret.HorizontalAlign.CENTER;
label.textFlow = new egret.HtmlTextParser().parser(
"<font size=12>媽媽再也不用擔心我在</font>" +
"<font color='#336699' size=60 strokecolor='#6699cc' stroke=2>Egret</font>" +
"<font fontfamily='楷體'>裡說一句話不能包含各種</font>" +
"<font color=0xff0000>五</font>" +
"<font color=0x00ff00>彩</font>" +
"<font color=0xf000f0>繽</font>" +
"<font color=0x00ffff>紛</font>" +
"<font>、\n</font>" +
"<font size=36>大</font>" +
"<font size=6>小</font>" +
"<font size=16>不</font>" +
"<font size=24>一</font>" +
"<font italic='true' color=0x00ff00>格</font>" +
"<font size=16 color=0xf000f0>式</font>" +
"<font i='true' color=0xf06f00>各</font>" +
"<font fontfamily='楷体'><b>樣</b></font>" +
"<font bold='true'>的</font>" +
"<font><i>文</i></font>" +
"<font b='true'>字</font>" +
"<font>了!</font>"
);
this.addChild(label);
}
}
沒有留言:
張貼留言