core-egret.BlendMode

egret.BlendMode 使用範例, 包含 ADD, ERASE 等用法


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.x = 50;
        shape2.blendMode = egret.BlendMode.ADD; // 設置混合模式為疊加效果
        this.addChild(shape2);

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

        const shape4 = new egret.Shape;
        shape4.graphics.beginFill(0);
        shape4.graphics.drawCircle(50,50,50);
        shape4.graphics.endFill();
        shape4.x = 50;
        shape4.y = 100;
        shape4.blendMode = egret.BlendMode.ERASE; // 設置混合模式為擦除效果
        this.addChild(shape4);
    }

}

spacer

沒有留言:

張貼留言