core-egret.TouchEvent

egret.TouchEvent 使用範例


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 給你最乾淨的程式碼, 從這行以下開始寫喔 ---

        let lb = new eui.Label('點我測試');
        lb.addEventListener(egret.TouchEvent.TOUCH_BEGIN, ()=>console.log('begin'), this); // 剛觸摸
        lb.addEventListener(egret.TouchEvent.TOUCH_MOVE, ()=>console.log('move'), this); // 觸摸後移動
        lb.addEventListener(egret.TouchEvent.TOUCH_END, ()=>console.log('end'), this); // 按鈕範圍內放開
        lb.addEventListener(egret.TouchEvent.TOUCH_TAP, ()=>console.log('tap'), this); // 觸摸並放開
        lb.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, ()=>console.log('release outside'), this); // 按鈕範圍外放開
        this.addChild(lb);

    }

}

spacer

沒有留言:

張貼留言