Skip to main content

Class: PositionComponent

Defined in: common/components/position-component.ts:7

Component to represent the position of an entity in 2D space.

Extends

Implements

Constructors

Constructor

new PositionComponent(x, y): PositionComponent

Defined in: common/components/position-component.ts:17

Creates an instance of PositionComponent.

Parameters

x

number = 0

The x-coordinate of the position.

y

number = 0

The y-coordinate of the position.

Returns

PositionComponent

Overrides

Vector2.constructor

Properties

name

name: symbol

Defined in: common/components/position-component.ts:8

The unique name of the component.

Implementation of

Component.name


x

x: number

Defined in: math/vector2.ts:7

The x-coordinate component of the vector

Inherited from

Vector2.x


y

y: number

Defined in: math/vector2.ts:10

The y-coordinate component of the vector

Inherited from

Vector2.y


symbol

readonly static symbol: typeof symbol

Defined in: common/components/position-component.ts:10

Accessors

down

Get Signature

get static down(): Vector2

Defined in: math/vector2.ts:104

Returns a unit vector pointing downward (0, -1).

Returns

Vector2

Inherited from

Vector2.down


left

Get Signature

get static left(): Vector2

Defined in: math/vector2.ts:111

Returns a unit vector pointing left (-1, 0).

Returns

Vector2

Inherited from

Vector2.left


one

Get Signature

get static one(): Vector2

Defined in: math/vector2.ts:132

Returns a vector with components of 1 (1, 1).

Returns

Vector2

Inherited from

Vector2.one


Get Signature

get static right(): Vector2

Defined in: math/vector2.ts:118

Returns a unit vector pointing right (1, 0).

Returns

Vector2

Inherited from

Vector2.right


up

Get Signature

get static up(): Vector2

Defined in: math/vector2.ts:97

Returns a unit vector pointing upward (0, 1).

Returns

Vector2

Inherited from

Vector2.up


zero

Get Signature

get static zero(): Vector2

Defined in: math/vector2.ts:125

Returns a zero vector (0, 0).

Returns

Vector2

Inherited from

Vector2.zero

Methods

add()

add(value): Vector2

Defined in: math/vector2.ts:39

Returns a new vector that is the sum of this vector and another vector.

Parameters

value

Vector2

The vector to add

Returns

Vector2

A new Vector2 representing the sum

Inherited from

Vector2.add


clone()

clone(): Vector2

Defined in: math/vector2.ts:179

Creates a deep copy of this vector.

Returns

Vector2

A new Vector2 with the same component values

Inherited from

Vector2.clone


distanceTo()

distanceTo(other): number

Defined in: math/vector2.ts:213

Calculates the distance between this vector and another vector.

Parameters

other

Vector2

The other vector

Returns

number

The distance between the two vectors

Inherited from

Vector2.distanceTo


divide()

divide(scalar): Vector2

Defined in: math/vector2.ts:87

Divides this vector by a scalar value.

Parameters

scalar

number

The scalar value to divide by

Returns

Vector2

A new Vector2 divided by the scalar

Inherited from

Vector2.divide


equals()

equals(value): boolean

Defined in: math/vector2.ts:196

Checks if this vector is equal to another vector.

Parameters

value

Vector2

The vector to compare

Returns

boolean

True if the vectors have the same components, false otherwise

Inherited from

Vector2.equals


floorComponents()

floorComponents(): Vector2

Defined in: math/vector2.ts:171

Returns a new vector with components rounded down to the nearest integer.

Returns

Vector2

A new Vector2 with floored components

Inherited from

Vector2.floorComponents


magnitude()

magnitude(): number

Defined in: math/vector2.ts:140

Calculates the magnitude (length) of this vector.

Returns

number

The magnitude of the vector

Inherited from

Vector2.magnitude


magnitudeSquared()

magnitudeSquared(): number

Defined in: math/vector2.ts:149

Calculates the squared magnitude of this vector. This is faster than magnitude() as it avoids the square root.

Returns

number

The squared magnitude of the vector

Inherited from

Vector2.magnitudeSquared


multiply()

multiply(scalar): Vector2

Defined in: math/vector2.ts:63

Multiplies this vector by a scalar value.

Parameters

scalar

number

The scalar value to multiply by

Returns

Vector2

A new Vector2 scaled by the input value

Inherited from

Vector2.multiply


multiplyComponents()

multiplyComponents(vector): Vector2

Defined in: math/vector2.ts:75

Multiplies this vector's components by another vector's components.

Parameters

vector

Vector2

The vector to multiply components with

Returns

Vector2

A new Vector2 with multiplied components

Inherited from

Vector2.multiplyComponents


normalize()

normalize(): Vector2

Defined in: math/vector2.ts:157

Returns a normalized (unit length) version of this vector.

Returns

Vector2

A new Vector2 with magnitude 1 in the same direction

Inherited from

Vector2.normalize


rotate()

rotate(angleInRadians): Vector2

Defined in: math/vector2.ts:222

rotates this vector by a given angle in radians.

Parameters

angleInRadians

number

The angle in radians to rotate the vector

Returns

Vector2

A new Vector2 representing the rotated vector

Inherited from

Vector2.rotate


set()

set(value): PositionComponent

Defined in: math/vector2.ts:27

Sets this vector's components to match another vector.

Parameters

value

Vector2

The vector to copy components from

Returns

PositionComponent

This vector for chaining

Inherited from

Vector2.set


subtract()

subtract(value): Vector2

Defined in: math/vector2.ts:51

Returns a new vector that is the difference between this vector and another vector.

Parameters

value

Vector2

The vector to subtract

Returns

Vector2

A new Vector2 representing the difference

Inherited from

Vector2.subtract


toFloat32Array()

toFloat32Array(): Float32Array

Defined in: math/vector2.ts:204

Converts the 2d vector to a glsl-compatible float32 array.

Returns

Float32Array

The 2d vector array (e.g. [5, 3] for a new Vector2(5, 3)).

Inherited from

Vector2.toFloat32Array


toString()

toString(): string

Defined in: math/vector2.ts:187

Returns a string representation of this vector.

Returns

string

A string in the format "(x, y)" with components rounded to 1 decimal place

Inherited from

Vector2.toString