Javascript 创建JS中drawPolygon的备选方案是什么?此功能是否已更改为其他功能?

Javascript 创建JS中drawPolygon的备选方案是什么?此功能是否已更改为其他功能?,javascript,angular,canvas,createjs,easeljs,Javascript,Angular,Canvas,Createjs,Easeljs,希望你做得很好,今天对你很好。我的场景是,我们在旧的Angular js项目中使用create js library绘制形状,代码如下: polygonGraphics(){ var g = new createjs.Graphics(); g.setStrokeStyle(2); g.beginStroke(createJS.Graphics.getRGB(255,0,0)) g.beginFill("#34343"); g.drawPolygon(0,0,cus

希望你做得很好,今天对你很好。我的场景是,我们在旧的Angular js项目中使用create js library绘制形状,代码如下:

polygonGraphics(){
 var g = new createjs.Graphics();
 g.setStrokeStyle(2);
 g.beginStroke(createJS.Graphics.getRGB(255,0,0))
 g.beginFill("#34343");
 g.drawPolygon(0,0,customData)
}
上述代码在旧的Angular Js项目中运行良好

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


任何帮助都将不胜感激。提前谢谢你

我肯定找到了使用的代码。这是完整的工作代码,这是我需要的。您是否知道,如何将此代码添加到我的typescript文件中,以便使用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, y, 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, y, points));
};

谢谢:)

我快速搜索了一下,发现
Graphics
对象有,但看不到drawPolygon。可能是自定义功能。@ChrisG谢谢您的评论。你说得对。这就是他们正在使用的。有什么想法吗?我如何在我的打字脚本中添加这段代码并使其工作?只需在包含主脚本后插入代码,就像小提琴一样。