Skip to main content

Class: Line

shapes/line.Line

Represents a line in 2D space.

Can have textures and varying line thickness as a Line is really just a wrapper around Rect.

Using setWidth, setHeight, setRotation or setPosition on a Line may lead to unexpected behaviour.

Hierarchy

Constructors

constructor

โ€ข new Line(start, end, weight)

Create a Line with a start and end point.

All values are in world space, including weight.

Parameters

NameTypeDescription
startvec2The start point of the line
endvec2The end point of the line
weightnumberThe weight of the line's stroke (thickness)

Overrides

Rect.constructor

Defined in

src/shapes/line.ts:27

โ€ข new Line(start, direction, length, weight)

Create a Line with a start and end point.

All values are in world space, including weight.

Parameters

NameTypeDescription
startvec2The start point of the line
directionvec2-
lengthnumber-
weightnumberThe weight of the line's stroke (thickness)

Overrides

Rect.constructor

Defined in

src/shapes/line.ts:29

โ€ข new Line(start, angle, length, weight)

Create a Line with a start and end point.

All values are in world space, including weight.

Parameters

NameTypeDescription
startvec2The start point of the line
anglenumber-
lengthnumber-
weightnumberThe weight of the line's stroke (thickness)

Overrides

Rect.constructor

Defined in

src/shapes/line.ts:31

Properties

end

โ€ข Private end: vec2

Defined in

src/shapes/line.ts:15


listeners

โ€ข Protected listeners: Object = {}

Index signature

โ–ช [index: string]: Listener[]

Inherited from

Rect.listeners

Defined in

src/object2d.ts:32


opacity

โ€ข opacity: number = 1

Opacity of the shape.

This is an opacity of the whole shape which is applied to the shape's entire texture equally.

Range is 0 (completely transparent) to 1 (completely opaque)

Inherited from

Rect.opacity

Defined in

src/shapes/shape.ts:28


start

โ€ข Private start: vec2

Defined in

src/shapes/line.ts:14


texture

โ€ข texture: Texture = defaultTexture

Inherited from

Rect.texture

Defined in

src/shapes/shape.ts:19


weight

โ€ข Private weight: number

Defined in

src/shapes/line.ts:16

Methods

addEventListener

โ–ธ addEventListener(event, listener): boolean

Executes a function when an event is fired.

Parameters

NameTypeDescription
eventstringThe event to listen for
listenerListenerThe function to execute when the event fired

Returns

boolean

Wether or not the listener was added

Inherited from

Rect.addEventListener

Defined in

src/object2d.ts:209


createFromAngle

โ–ธ Private createFromAngle(start, angle, length, weight): void

Parameters

NameType
startvec2
anglenumber
lengthnumber
weightnumber

Returns

void

Defined in

src/shapes/line.ts:67


createFromDirection

โ–ธ Private createFromDirection(start, direction, length, weight): void

Parameters

NameType
startvec2
directionvec2
lengthnumber
weightnumber

Returns

void

Defined in

src/shapes/line.ts:61


createFromStartEnd

โ–ธ Private createFromStartEnd(start, end, weight): void

Parameters

NameType
startvec2
endvec2
weightnumber

Returns

void

Defined in

src/shapes/line.ts:46


fireEvent

โ–ธ fireEvent(event, ...e): void

Executes all listeners attached to a given event.

Parameters

NameTypeDescription
eventstringThe event to fire
...eanyThe data to pass to each event listener

Returns

void

Inherited from

Rect.fireEvent

Defined in

src/object2d.ts:185


getBaseVertices

โ–ธ getBaseVertices(): vec2[]

Calculates the base vertices of the rectangle.

These vertices are the base vertices for a quad, scaled to the width and height of the {@link Rectangle} instance.

Returns

vec2[]

The rectangles base vertices

Inherited from

Rect.getBaseVertices

Defined in

src/shapes/rect.ts:84


getEnd

โ–ธ getEnd(): vec2

Gets the point at which the line ends.

Returns

vec2

The end point of the line

Defined in

src/shapes/line.ts:127


getEventListeners

โ–ธ getEventListeners(event): Listener[]

Gets the listeners attached to an event.

Parameters

NameType
eventstring

Returns

Listener[]

An array of listeners attached to the given event

Inherited from

Rect.getEventListeners

Defined in

src/object2d.ts:198


getEvents

โ–ธ getEvents(): string[]

Gets the events that can be listened to on the object.

Returns

string[]

The events the object supports

Inherited from

Rect.getEvents

Defined in

src/object2d.ts:175


getHeight

โ–ธ getHeight(): number

Gets the rectangle's height in world space units.

Returns

number

The rectangle's height in world space

Inherited from

Rect.getHeight

Defined in

src/shapes/rect.ts:162


getIndices

โ–ธ getIndices(offset?): Uint16Array

Gets the rect's vertex indices for drawing using element arrays.

Parameters

NameTypeDefault valueDescription
offsetnumber0An offset to apply to each index

Returns

Uint16Array

The rect's vertex indices with the given offset added to each index

Inherited from

Rect.getIndices

Defined in

src/shapes/rect.ts:109


getPoints

โ–ธ getPoints(): vec2[]

Calculates the bounding points of the Shape instance.

NOTE: The shape's vertices are recalculated every time this function is called.

Returns

vec2[]

The bounding points of the box

Inherited from

Rect.getPoints

Defined in

src/shapes/shape.ts:136


getPosition

โ–ธ getPosition(): vec2

Gets the object's position.

Returns

vec2

The object's position as a vec2

Inherited from

Rect.getPosition

Defined in

src/object2d.ts:82


getRotation

โ–ธ getRotation(): number

Gets the object's rotation as a number in radians relative to y+.

Returns

number

The object's rotation

Inherited from

Rect.getRotation

Defined in

src/object2d.ts:139


getStart

โ–ธ getStart(): vec2

Gets the point at which the line begins.

Returns

vec2

The start point of the line

Defined in

src/shapes/line.ts:109


getUVCoords

โ–ธ getUVCoords(): Float32Array

Calculates the rects's UV coords to be used for texture rendering.

Returns

Float32Array

the rect's UV coords

Inherited from

Rect.getUVCoords

Defined in

src/shapes/rect.ts:118


getVertices

โ–ธ getVertices(): number[]

Calculates the shape's vertices in local space.

Returns

number[]

The shape's vertices

Inherited from

Rect.getVertices

Defined in

src/shapes/shape.ts:57


getVerticesClipSpace

โ–ธ getVerticesClipSpace(origin, scale, rotation?, camera?): number[]

Calculates the shape's vertices relative to the provided origin in world space.

Parameters

NameTypeDescription
originvec2The origin to calculate the vertices relative to, should be a world position
scalevec2The vector to scale the world space vertices by to obtain clip space values
rotation?numberAn optional rotation to apply to the vertices
camera?CameraAn optional camera to get vertices relative to

Returns

number[]

The shape's vertices relative to the provided origin in clip space

Inherited from

Rect.getVerticesClipSpace

Defined in

src/shapes/shape.ts:87


getVerticesWorld

โ–ธ getVerticesWorld(origin, rotation?, returnVecs?): number[] | vec2[]

Calculates the rect's vertices relative to the provided origin in world space.

Parameters

NameTypeDefault valueDescription
originvec2undefinedThe origin to calculate the vertices relative to, should be a world position
rotation?numberundefinedAn optional world space rotation to apply to the vertices
returnVecsbooleanfalseWether or not to return the vertices as vec2s or raw numbers

Returns

number[] | vec2[]

The rect's vertices relative to the provided origin in world space

Inherited from

Rect.getVerticesWorld

Defined in

src/shapes/rect.ts:51


getWeight

โ–ธ getWeight(): number

Gets the weight of the line (thickness).

Returns

number

The stroke weight of the line

Defined in

src/shapes/line.ts:91


getWidth

โ–ธ getWidth(): number

Gets the rectangle's width in world space units.

Returns

number

The rectangle's width in world space

Inherited from

Rect.getWidth

Defined in

src/shapes/rect.ts:140


moveRight

โ–ธ moveRight(dist): void

Moves the object's position right (x+) relative to it's rotation.

Parameters

NameTypeDescription
distnumberThe distance to move right, can be + or -

Returns

void

Inherited from

Rect.moveRight

Defined in

src/object2d.ts:100


moveUp

โ–ธ moveUp(dist): void

Moves the object's position up (y+) relative to it's rotation.

Parameters

NameTypeDescription
distnumberThe distance to move up, can be + or -

Returns

void

Inherited from

Rect.moveUp

Defined in

src/object2d.ts:114


removeEventListener

โ–ธ removeEventListener(event, listener): boolean

Removes a listener from an event.

Parameters

NameTypeDescription
eventstringThe event the listener is attached to
listenerListenerThe listener to remove

Returns

boolean

Wether or not the listener was removed

Inherited from

Rect.removeEventListener

Defined in

src/object2d.ts:223


render

โ–ธ render(position?, rotation?, zIndex?): void

Renders the shape using the Renderer.

Parameters

NameTypeDescription
position?vec2The x and y position to render the shape at
rotation?numberThe rotation to apply to the rendered shape
zIndex?numberThe z position of the rendered shape

Returns

void

Inherited from

Rect.render

Defined in

src/shapes/shape.ts:41


rotate

โ–ธ rotate(angle): void

Increments the object's rotation by an angle in radians.

Parameters

NameTypeDescription
anglenumberThe angle to rotate by in radians

Returns

void

Inherited from

Rect.rotate

Defined in

src/object2d.ts:148


setEnd

โ–ธ setEnd(end): void

Sets the end point of the line.

Parameters

NameTypeDescription
endvec2The new end point of the line

Returns

void

Defined in

src/shapes/line.ts:118


setHeight

โ–ธ setHeight(height): void

Sets the rectangle's height.

throws When the the provided height is < 0

Parameters

NameTypeDescription
heightnumberThe rectangle's new height

Returns

void

Inherited from

Rect.setHeight

Defined in

src/shapes/rect.ts:151


setPosition

โ–ธ setPosition(pos): void

Sets the object's position.

Parameters

NameTypeDescription
posvec2The object's new position

Returns

void

Inherited from

Rect.setPosition

Defined in

src/object2d.ts:43


setPositionX

โ–ธ setPositionX(x): void

Sets the x component of the object's position.

Parameters

NameTypeDescription
xnumberThe object's new x coordinate

Returns

void

Inherited from

Rect.setPositionX

Defined in

src/object2d.ts:56


setPositionY

โ–ธ setPositionY(y): void

Sets the y component of the object's position.

Parameters

NameTypeDescription
ynumberThe object's new y coordinate

Returns

void

Inherited from

Rect.setPositionY

Defined in

src/object2d.ts:69


setRotation

โ–ธ setRotation(angle): void

Sets the object's rotation.

Parameters

NameTypeDescription
anglenumberThe object's new rotation

Returns

void

Inherited from

Rect.setRotation

Defined in

src/object2d.ts:128


setStart

โ–ธ setStart(start): void

Sets the starting point of the line.

Parameters

NameTypeDescription
startvec2The new starting point of the line

Returns

void

Defined in

src/shapes/line.ts:100


setWeight

โ–ธ setWeight(weight): void

Sets the weight of the line (thickness).

Parameters

NameTypeDescription
weightnumberThe new weight of the line

Returns

void

Defined in

src/shapes/line.ts:79


setWidth

โ–ธ setWidth(width): void

Sets the rectangle's width.

throws When the the provided width is < 0

Parameters

NameTypeDescription
widthnumberThe rectangle's new width

Returns

void

Inherited from

Rect.setWidth

Defined in

src/shapes/rect.ts:129


setupEvents

โ–ธ Protected setupEvents(): void

Sets all the events that can be used in listeners.

Listeners can be added for an event using:

   this.listeners.eventName = [];

example Setup listeners for "position" and "rotate" events. this.listeners.position = []; this.listeners.rotate = [];

Returns

void

Inherited from

Rect.setupEvents

Defined in

src/object2d.ts:165


translate

โ–ธ translate(v): void

Translates the object by the provided vector.

Parameters

NameTypeDescription
vvec2The vector to translate by

Returns

void

Inherited from

Rect.translate

Defined in

src/object2d.ts:91