Deyan Dimov
Deyan Dimov

Reputation: 33

KineticJS: Line.getPoints() method does not return an array of points. Why?

The getPoints() method on a Line object in KineticJS does not return an array of points. I have created a fiddle illustrating the problem.

In the fiddle, I have placed a button that runs the test() function.

My code is as follows:

var stage = new Kinetic.Stage({
container: 'main',
width: 1200,
height: 400,
});

var linesLayer = new Kinetic.Layer();
var textLayer = new Kinetic.Layer();

var testLine = new Kinetic.Line({
     points: [100, 100, 100, 200],

    stroke: 'red',
    strokeWidth: 3});

linesLayer.add(testLine);

function test(){

var context = textLayer.getContext();
context.font = '18pt Calibri';
context.fillStyle = 'black';

context.fillText(testLine.getPoints().join(),100,350);

}
stage.add(linesLayer);

stage.add(textLayer);

The result displayed on the screen when the test() function runs is [object Object],[object Object] and I'm not sure why or how to deal with is. Help?

Thanks guys!

Upvotes: 0

Views: 667

Answers (1)

irie
irie

Reputation: 472

in fact it does. It returns an array of two objects (as you could already see in your output), and everyone of these objects contains two values: x and y.

Here a screenshot of the console if you log testLine.getPoints():

enter image description here

Upvotes: 1

Related Questions