在create JS中drawPolygon的替代方法是什么?此功能是否已更改为其他功能?

问题描述

希望您一切都好,今天对您有好处。我的情况是,我们在旧的Angular JS项目中使用了create js Create JS库来绘制形状,代码如下:

polygonGraphics(){
 var g = new createjs.Graphics();
 g.setstrokeStyle(2);
 g.beginstroke(createJS.Graphics.getRGB(255,0))
 g.beginFill("#34343");
 g.drawpolygon(0,customData)
}

上面的代码在旧的Angular Js项目中可以正常工作。

现在,当我尝试在新的Angular 2项目中使用此代码时,编译器会说 g.drawpolygon 不存在。 是否在任何版本中将其更改为其他内容?我尝试查找,但是没有得到太多信息。

任何帮助将不胜感激。预先谢谢你

解决方法

我当然已经发现使用了什么代码。这是完整的工作代码drawPolygon,这就是我所需要的。您有什么想法,如何在我的打字稿文件中添加此代码,以便可以使用g.drawPolygon()正常工作?这是代码,链接中有工作示例。

    (createjs.Graphics.Polygon = function(x,y,points) {
    this.x = x;
    this.y = y;
    this.points = points;
}).prototype.exec = function(ctx) {
    // Start at the end to simplify loop
    var end = this.points[this.points.length - 1];
    ctx.moveTo(end.x,end.y);
    this.points.forEach(function(point) {
        ctx.lineTo(point.x,point.y);
    });
};
createjs.Graphics.prototype.drawPolygon = function(x,args) {
    var points = [];
    if (Array.isArray(args)) {
        args.forEach(function(point) {
            point = Array.isArray(point) ? {x:point[0],y:point[1]} : point;
            points.push(point);
        });
    } else {
        args = Array.prototype.slice.call(arguments).slice(2);
        var px = null;
        args.forEach(function(val) {
            if (px === null) {
                px = val;
            } else {
                points.push({x: px,y: val});
                px = null;
            }
        });
    }
    return this.append(new createjs.Graphics.Polygon(x,points));
};

谢谢:)