egret.HashObject 使用範例
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 h1: egret.HashObject = new egret.Shape();
const h2: egret.HashObject = new egret.HashObject();
const h3: egret.HashObject = h1;
const h4: egret.HashObject = h3;
// hashCode 是識別物件的唯一碼, 用於比對與查找, 尤其多個變數引用同一物件時, 可以用 hashCode 確認是否是同一物件
// hashCode 由 1 開始, 每建立一個物件, hashCode 會 +1, 並賦予該物件
// 從 207 得知 h2 為整個 egret 第 207 個創建實例物件
console.log(h1.hashCode, h2.hashCode, h3.hashCode, h4.hashCode); // 204 207 204 204
console.log(h1.hashCode == h2.hashCode); // false, 表示不同物件, 反之為相同物件
}
}
沒有留言:
張貼留言