Вопрос

Is it possible to retrieve these points from a drawn line? The API didn't really help me.

var line = new createjs.Graphics();
line.beginStroke( 'black' );
line.moveTo( 0, 0 );
line.lineTo( 100, 100 );

Right now I'm creating an instance of the Point class and use the coordinates as parameters.

var point1 = new Point(0, 0);
var point2 = new Point(100, 100);

var line = new createjs.Graphics();
line.beginStroke( 'black' );
line.moveTo( point1.x, point1.y );
line.lineTo( point2.x, point2.y );
Это было полезно?

Решение

While it would be possible in theory, to retrieve those coordinates, you are far better of saving them as custom objects (Points for example, as you do already).


The Graphics-object saves those draw-instructions and coordinates in Commands (Command(f, params, path)) - and all active commands are saved in an array: line._activeInstructions

You would have to go through the first and the last command and retrieve the command's params-array, those would be your points. But this would only work in your case of a simple line. And since this uses internal variables and methods of the Graphics-object, I highly recommend not to do it this way. Also I'd recommend you to keep the readability of your code in this case instead of trying to save some memory by not using 2 Points with an pretty much unmeasureable memory-effect.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top