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();
    }
}

 

posted on 2018-02-01 16:39  被遗忘的优雅  阅读(598)  评论(0编辑  收藏  举报