To create a line segment I just need to pass the four arguments for the x, and y positions of the two points that make up the Line. To draw the line I can use Phasers Graphics display objects to get that done.
Each line has a start point, and an end point and that is where the line.start, and that is of course where the line.start, and line.end objects come into play. Now that I have the basics done, it would be nice to know about some of the methods that are available for Lines.
This method will return a Point that is the midPoint of the line that I call the method on.
Every Line has a start and end point getting this is a simple as just cheking out these objects in the instance of Line.
In addition to being helpful just because they are objects that have the properties I often need, both of these Objects are instances of Phaser.Point, and as such have all the properties, and method of that constructor as well.
As the names imply these properties simply just give the boundaries of the line.
If I have an instance of Line there is no need to use the distance formula to get it’s length, there is all ready a property for that.
Another great thing about an instance of Line is that I can use it to find the angle a line is heading from it’s start point to end point by just checking the angle property
There are some methods attached to the constructor function that are not part of an instance one of theme is the interest methods which comes in handy for collision detection, or to just find a certain point at which two lines meet.
This method will return null if an intersection is not found.
The Line constructor Is very helpful when working with lines, just about all the methods I can think of are there. It’s two bad I ran into some problems with a few of the methods, when it comes to finding if a point is on a line or not, but disappointments with phaser are rare so far as I explore Phaser.