egret.Sprite 使用範例
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 給你最乾淨的程式碼, 從這行以下開始寫喔 ---
// Sprite 具有 egret.DisplayObjectContainer 功能可以 addChild
// Sprite 可以像 egret.Shape 具有繪圖功能
// 子物件的繪圖會蓋在 Sprite 父物件繪圖上
const parentSprite = new egret.Sprite;
parentSprite.graphics.beginFill(0);
parentSprite.graphics.drawRect(0, 0, 100, 100);
parentSprite.graphics.endFill();
this.addChild(parentSprite);
const s = new egret.Shape;
s.graphics.beginFill(0xFFCC00);
s.graphics.drawCircle(0, 0, 20);
s.graphics.endFill();
parentSprite.addChild(s);
}
}
沒有留言:
張貼留言