egret.localStorage.globalFunction 使用範例
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 給你最乾淨的程式碼, 從這行以下開始寫喔 ---
egret.localStorage.setItem('gameData1', '1');
egret.localStorage.setItem('gameData2', '2');
egret.localStorage.setItem('gameData3', '3');
egret.log(egret.localStorage.getItem('gameData1')); // 1
egret.log(egret.localStorage.getItem('gameData2')); // 2
egret.log(egret.localStorage.getItem('gameData3')); // 3
egret.localStorage.removeItem('gameData1'); // 刪除指定資料
egret.log(egret.localStorage.getItem('gameData1')); // null
egret.log(egret.localStorage.getItem('gameData2')); // 2
egret.log(egret.localStorage.getItem('gameData3')); // 3
egret.localStorage.clear(); // 刪除全部資料
egret.log(egret.localStorage.getItem('gameData2')); // null
egret.log(egret.localStorage.getItem('gameData3')); // null
}
}
沒有留言:
張貼留言