egret.Capabilities 範例
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 isMobile = egret.Capabilities.isMobile;
const language = egret.Capabilities.language;
const os = egret.Capabilities.os;
const runtimeType = egret.Capabilities.runtimeType;
const engineVersion = egret.Capabilities.engineVersion;
const renderMode = egret.Capabilities.renderMode;
const boundingClientWidth = egret.Capabilities.boundingClientWidth;
const boundingClientHeight = egret.Capabilities.boundingClientHeight;
// 建立文字物件
const lb = new eui.Label;
lb.x = 50;
lb.y = 100;
lb.text = 'IsMobile: ' + isMobile + '\n' + // false
'Language: ' + language + '\n' + // zh-TW
'OS: ' + os + '\n' + // mac os
'RuntimeType: ' + runtimeType + '\n' + // web
'EngineVersion: ' + engineVersion + '\n' + // 5.3.xx
'RenderMode: ' + renderMode + '\n' + // webgl 或 canvas
'BoundingClientWidth: ' + boundingClientWidth + '\n' + // 同等 div.egret-player 容器寬度
'BoundingClientHeight: ' + boundingClientHeight; // 同等 div.egret-player 容器高度
this.addChild(lb);
}
}
沒有留言:
張貼留言