白鹭引擎 - 矢量绘图 ( graphics )

class Main extends egret.DisplayObjectContainer {

    /**
     * Main 类构造器, 初始化的时候自动执行, ( 子类的构造函数必须调用父类的构造函数 super )
     * constructor 是类的构造函数, 类在实例化的时候调用
     * egret.Event.ADDED_TO_STAGE, 在将显示对象添加到舞台显示列表时调度
     */
    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
    }

    /**
     * 1, 调用 显示对象.graphics 属相是一个 Graphics 对象, 用于绘制矢量图
     * 2, Graphics 对象含有大量绘制矢量图的方法, 具体方法看最后面的图
     * 3, 线段的绘制, 绘制前需要制定样式  lineStyle( 粗细值, 颜色 )
     * ---graphics.moveTo(x, y) 指定起点线段, lineTo 指定下一个点
     * 4, graphics.endFill() 方法结束当前绘画的设定, 并绘制
     * 5, graphics.curveTo(x1, y1, x2, y2) 方法绘制二次贝塞尔曲线
     * 6, graphics.drawArc(x, y, 半径, 起点的角度, 重点的角度, 是否逆时针绘制)
     * 7, graphics.clear() 方法用于清空显示对象的所有绘制
     */
    private onAddToStage(event: egret.Event) {

        var shp:egret.Shape = new egret.Shape();
        shp.graphics.lineStyle(10, 0x00ff00);
        shp.graphics.moveTo(100, 100);
        shp.graphics.lineTo(200, 200);
        shp.graphics.lineTo(300, 200);
        shp.graphics.curveTo(400, 400, 500, 200);
        shp.graphics.endFill();
        this.addChild(shp);

        var shape1:egret.Shape = new egret.Shape();
        shape1.graphics.beginFill(0xffff00);
        shape1.graphics.drawArc(100, 100, 50, 0, Math.PI, false);
        shape1.graphics.endFill();
        this.addChild(shape1);

        shp.graphics.clear();
    }
}

 

转载于:https://www.cnblogs.com/lovling/p/8399808.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值