core-egret.ChildrenSortMode⚡

目前測試方法無效,歡迎協助解答


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 shape1 = new egret.Shape;
        shape1.graphics.beginFill(0xFF0000);
        shape1.graphics.drawCircle(50,50,50);
        shape1.graphics.endFill();
        this.addChild(shape1);

        const shape2 = new egret.Shape;
        shape2.graphics.beginFill(0x00FF00);
        shape2.graphics.drawCircle(50,50,50);
        shape2.graphics.endFill();
        shape2.y = 30;
        this.addChild(shape2);

        const shape3 = new egret.Shape;
        shape3.graphics.beginFill(0x0000FF);
        shape3.graphics.drawCircle(50,50,50);
        shape3.graphics.endFill();
        shape3.y = 60;
        this.addChild(shape3);

        const btnIncrease = new eui.Button;
        btnIncrease.label = 'y遞增';
        btnIncrease.y = 200;
        btnIncrease.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>this.setChildrenSortMode(egret.ChildrenSortMode.INCREASE_Y),this);
        this.addChild(btnIncrease);

        const btnDecrease = new eui.Button;
        btnDecrease.label = 'y遞減';
        btnDecrease.y = 250;
        btnDecrease.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>this.setChildrenSortMode(egret.ChildrenSortMode.DECREASE_Y),this);
        this.addChild(btnDecrease);
    }

}

補充說明:經過網頁測試與原生測試皆無效


        // egret.js 裡
        DisplayObjectContainer.prototype.setChildrenSortMode = function (value) {
        	// 網頁模式下 egret.nativeRender 為 undefined 所以 if 判斷不會通過(所以網頁版應該沒有實作此功能), 而 ios 專案下可以通過但此方法仍然無效
            if (egret.nativeRender && this.$nativeDisplayObject.setChildrenSortMode) {
                egret.ExternalInterface.call("sendToNative", this.$nativeDisplayObject.setChildrenSortMode.toString()); // 補上這句
                this.$nativeDisplayObject.setChildrenSortMode(value);
            }
        };
        
        // ios 專案的 NSLog 打印出如下,看不懂無解
        // 2020-07-21 16:56:49.737727+0800 test[38313:14719418] Native get message: function (t){var n=0;"increaseY"===t?n=1:"decreaseY"===t&&(n=2),_<v+3&&a(),T[v++]=5,T[v++]=this.id,T[v++]=n,E++}
        
spacer

沒有留言:

張貼留言