简体   繁体   English

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

[英]What is the alternate for drawPolygon in create JS ? Has this function been changed to something else?

Hope you're doing well and day has been good for you.希望你过得很好,这一天对你来说很好。 My scenario is, we used create js Create JS library for drawing shapes in our old Angular JS project and the code is below:我的场景是,我们在旧的 Angular JS 项目中使用 create js Create JS库来绘制形状,代码如下:

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

This above code works fine in that old Angular Js project.上面的代码在旧的 Angular Js 项目中运行良好。

Now when I try to use this code in my new Angular 2 project, the compiler says, g.drawPolygon does not exist.现在,当我尝试在我的新 Angular 2 项目中使用此代码时,编译器说g.drawPolygon不存在。 Has this been changed to something else in any of its versions?这是否在其任何版本中更改为其他内容? I tried finding but didn't get much info on this.我试图找到,但没有得到太多关于这方面的信息。

Any help would be appreciated.任何帮助,将不胜感激。 Thank you in advance先感谢您

I certainly have found what code has been used.我当然已经找到使用了什么代码。 Here is the complete working code drawPolygon and this is what I need.这是完整的工作代码drawPolygon ,这就是我需要的。 Do you have any idea, how can I add this code in my typescript file so that it can work by using g.drawPolygon()?你有什么想法,我怎样才能在我的打字稿文件中添加这段代码,以便它可以通过使用 g.drawPolygon() 来工作? Here is the code and working example is in the link.这是代码和工作示例在链接中。

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

Thank you :)谢谢 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM