简体   繁体   中英

KineticJS Line Points as an argument

is there anyway to give the points of line with an array.

var line = new Kinetic.Line({
                points : [{
                    x : line_points_x,
                    y : line_points_y
                }],
                stroke : 'black',
                strokeWidth : 5,
                lineCap : 'round'
            });

I tried something but didn't work.I have 2 arrays that holds x and y points.

No. There are only 3 allowed structures.

[0,1,2,3] , [[0,1],[2,3]] and [{x:0,y:1},{x:2,y:3}]

So you have to do something like this:

var points = [];
for(var i=0; i<line_points_x.length; i++) {
   points.push( { x: line_points_x[i], y: line_points_y[i] } );
}

var line = new Kinetic.Line({
    points: points,
    stroke: 'black',
    strokeWidth: 5,
    lineCap: 'round'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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