Skip to main content

Class: TriangleCollider

physics/collider/triangle.TriangleCollider

Represents a triangle collider in 2D world space with a position and dimensions.

Hierarchy

Implements

Constructors

constructor

โ€ข new TriangleCollider(width, height, position?)

Creates a new TriangleCollider instance with a position and dimensions.

Parameters

NameTypeDescription
widthnumberThe width of the box
heightnumberThe height of the box
position?vec2The box's position in world space

Overrides

Triangle.constructor

Defined in

src/physics/collider/triangle.ts:18

Properties

listeners

โ€ข Protected listeners: Object = {}

Index signature

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

Implementation of

Collider.listeners

Inherited from

Triangle.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)

Implementation of

Collider.opacity

Inherited from

Triangle.opacity

Defined in

src/shapes/shape.ts:28


texture

โ€ข texture: Texture = defaultTexture

Implementation of

Collider.texture

Inherited from

Triangle.texture

Defined in

src/shapes/shape.ts:19

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

Implementation of

Collider.addEventListener

Inherited from

Triangle.addEventListener

Defined in

src/object2d.ts:209


findFurthestNeighbours

โ–ธ findFurthestNeighbours(direction): Object

Calculates the furthest point on the collider in a direction and it's neighbouring vertices on the collider.

Parameters

NameTypeDescription
directionvec2The direction in which to calculate the furthest point

Returns

Object

The furthest point on the collider in the given direction and its left and right neighbours

NameType
furthestvec2
leftvec2
rightvec2

Implementation of

Collider.findFurthestNeighbours

Defined in

src/physics/collider/triangle.ts:91


findFurthestPoint

โ–ธ findFurthestPoint(direction): vec2

Calculates the furthest point on the collider in a direction.

Parameters

NameTypeDescription
directionvec2The direction in which to calculate the furthest point

Returns

vec2

The furthest point on the collider in the given direction

Implementation of

Collider.findFurthestPoint

Defined in

src/physics/collider/triangle.ts:69


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

Implementation of

Collider.fireEvent

Inherited from

Triangle.fireEvent

Defined in

src/object2d.ts:185


getBaseVertices

โ–ธ getBaseVertices(): vec2[]

Calculates the base vertices of the triangle.

These are the vertices for a triangle scaled to the width and height of the Triangle instance.

Returns

vec2[]

The triangles base vertices

Implementation of

Collider.getBaseVertices

Inherited from

Triangle.getBaseVertices

Defined in

src/shapes/triangle.ts:87


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

Implementation of

Collider.getEventListeners

Inherited from

Triangle.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

Implementation of

Collider.getEvents

Inherited from

Triangle.getEvents

Defined in

src/object2d.ts:175


getHeight

โ–ธ getHeight(): number

Gets the triangle's height in world space units.

Returns

number

The triangle's height in world space

Inherited from

Triangle.getHeight

Defined in

src/shapes/triangle.ts:164


getIndices

โ–ธ getIndices(offset?): Uint16Array

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

Parameters

NameTypeDefault valueDescription
offsetnumber0An offset to apply to each index

Returns

Uint16Array

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

Implementation of

Collider.getIndices

Inherited from

Triangle.getIndices

Defined in

src/shapes/triangle.ts:111


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

Implementation of

Collider.getPoints

Inherited from

Triangle.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

Implementation of

Collider.getPosition

Inherited from

Triangle.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

Implementation of

Collider.getRotation

Inherited from

Triangle.getRotation

Defined in

src/object2d.ts:139


getUVCoords

โ–ธ getUVCoords(): Float32Array

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

Returns

Float32Array

the triangle's UV coords

Implementation of

Collider.getUVCoords

Inherited from

Triangle.getUVCoords

Defined in

src/shapes/triangle.ts:120


getVertices

โ–ธ getVertices(): number[]

Calculates the shape's vertices in local space.

Returns

number[]

The shape's vertices

Implementation of

Collider.getVertices

Inherited from

Triangle.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

Implementation of

Collider.getVerticesClipSpace

Inherited from

Triangle.getVerticesClipSpace

Defined in

src/shapes/shape.ts:87


getVerticesWorld

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

Calculates the triangle'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 triangle's vertices relative to the provided origin in world space

Implementation of

Collider.getVerticesWorld

Inherited from

Triangle.getVerticesWorld

Defined in

src/shapes/triangle.ts:50


getWidth

โ–ธ getWidth(): number

Gets the triangle's width in world space units.

Returns

number

The triangle's width in world space

Inherited from

Triangle.getWidth

Defined in

src/shapes/triangle.ts:142


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

Implementation of

Collider.moveRight

Inherited from

Triangle.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

Implementation of

Collider.moveUp

Inherited from

Triangle.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

Implementation of

Collider.removeEventListener

Inherited from

Triangle.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

Implementation of

Collider.render

Inherited from

Triangle.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

Implementation of

Collider.rotate

Inherited from

Triangle.rotate

Defined in

src/object2d.ts:148


setHeight

โ–ธ setHeight(height): void

Sets the triangle's height.

throws When the the provided height is < 0

Parameters

NameTypeDescription
heightnumberThe triangle's new height

Returns

void

Inherited from

Triangle.setHeight

Defined in

src/shapes/triangle.ts:153


setPosition

โ–ธ setPosition(pos): void

Sets the object's position.

Parameters

NameTypeDescription
posvec2The object's new position

Returns

void

Implementation of

Collider.setPosition

Inherited from

Triangle.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

Implementation of

Collider.setPositionX

Inherited from

Triangle.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

Implementation of

Collider.setPositionY

Inherited from

Triangle.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

Implementation of

Collider.setRotation

Inherited from

Triangle.setRotation

Defined in

src/object2d.ts:128


setWidth

โ–ธ setWidth(width): void

Sets the triangle's width.

throws When the the provided width is < 0

Parameters

NameTypeDescription
widthnumberThe triangle's new width

Returns

void

Inherited from

Triangle.setWidth

Defined in

src/shapes/triangle.ts:131


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

Implementation of

Collider.setupEvents

Inherited from

Triangle.setupEvents

Defined in

src/object2d.ts:165


supportPoint

โ–ธ supportPoint(c, direction): vec2

Calculates a support point on the minkowski difference in a given direction.

Parameters

NameTypeDescription
cColliderThe collider to test against
directionvec2The direction to use when calculating furthest points

Returns

vec2

The support point in the given direction for the Minkowski difference

Implementation of

Collider.supportPoint

Defined in

src/physics/collider/triangle.ts:54


testCollision

โ–ธ testCollision(c): CollisionResult

Checks if this triangle collider is colliding with another collider.

Parameters

NameTypeDescription
cColliderCollider to test collisions against

Returns

CollisionResult

CollisionResult with the results of the test

Implementation of

Collider.testCollision

Defined in

src/physics/collider/triangle.ts:28


translate

โ–ธ translate(v): void

Translates the object by the provided vector.

Parameters

NameTypeDescription
vvec2The vector to translate by

Returns

void

Implementation of

Collider.translate

Inherited from

Triangle.translate

Defined in

src/object2d.ts:91