Egret 遮罩 官网案例

本文介绍如何在Egret框架中利用遮罩技术实现图形的精确裁剪。通过创建矩形和圆形两个形状对象,将圆形作为遮罩应用于矩形上,从而达到圆形范围内的图形显示效果。此方法适用于游戏开发中需要精确控制图形显示区域的场景。
// 遮罩
module game {
    export class Test extends egret.DisplayObjectContainer {
        public constructor() {
            super();
            this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
        }
        private onAddToStage(event: egret.Event) {
            var square : egret.Shape = new egret.Shape();
            square.graphics.beginFill(0xff0000);
            square.graphics.drawRect(100,100,100,100);
            square.graphics.endFill();
            this.addChild(square);

            var circle:egret.Shape = new egret.Shape();
            circle.graphics.beginFill(0x0000ff);
            circle.graphics.drawCircle(150,150,25);
            circle.graphics.endFill();
            this.addChild(circle);
            square.mask = circle;
        }
    }
}

效果如下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值