Math utilities are exported from the mainDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/fraxel/llms.txt
Use this file to discover all available pages before exploring further.
fraxel package. The module provides Vector2 for 2D coordinates and directions, the VectorLike union type accepted by all JSX props that deal with positions and sizes, and the Color RGBA tuple type used by filter and tint props. You will use these types constantly when writing game logic, setting up collision shapes, or configuring raycasts. See also the Collision API and Filters guide for context on where each type appears.
Vector2
A mutable 2D vector. All mutating methods (add, subtract, multiply, normalize) modify the instance in place and return this for chaining. Non-mutating equivalents (toAdded, toSubtracted, toMultiplied) clone the vector first.
Constructor
The x-coordinate (horizontal axis, increasing rightward).
The y-coordinate (vertical axis, increasing downward in screen space).
Static factories
Returns a new
Vector2(0, 0). A fresh instance is returned each time — safe to mutate.Returns a new
Vector2(1, 1). Useful as a default scale or unit vector.Creates a
Vector2 from a plain Position object { x: number, y: number }. Handy when deserialising saved game state.Converts any
VectorLike value to a Vector2. See VectorLike below for the accepted forms.Properties
The x-coordinate. Publicly writable.
The y-coordinate. Publicly writable.
Mutating methods
All mutating methods returnthis for chaining.
Adds another
Vector2 component-wise, or adds a scalar to both x and y. Mutates in place.Subtracts another
Vector2 component-wise, or subtracts a scalar from both axes. Mutates in place.Multiplies component-wise by another
Vector2, or scales both axes by a scalar. Mutates in place.Scales the vector to unit length (magnitude = 1). If the vector is zero, it remains zero. Mutates in place.
Applies a function to each component independently. Mutates in place.
Non-mutating (clone) methods
These return a newVector2 and leave the original unchanged.
Returns a new vector equal to
this + arg.Returns a new vector equal to
this - arg.Returns a new vector equal to
this * arg.Returns a new vector with
fn applied to each component.Returns a deep copy of this vector with the same
x and y values.Comparison and serialisation
Returns
true if both x and y are strictly equal.Converts to a plain
{ x: number, y: number } object. Useful for serialisation.Practical examples
VectorLike
VectorLike is the union type accepted by any JSX prop that represents a 2D coordinate, size, or direction — position, size, direction, scale, etc. This means you can write positions as:
Vector2.vectorize() on every VectorLike prop before using it:
| Input form | Converted to |
|---|---|
Vector2 | Returned as-is |
[number, number] | new Vector2(arr[0], arr[1]) |
{ x: number, y: number } | Vector2.fromJSON(pos) |
number | new Vector2(n, n) — same value for both axes |
Color
[r, g, b, a] where every channel is in the range 0–1 (not 0–255). Used by filter and tint props that accept colour values.
0 is fully transparent, 1 is fully opaque. See the Filters guide for nodes that accept Color props.
Position interface
vector.toJSON() and accepted anywhere a lightweight { x, y } object is needed instead of a full Vector2.
Related guides
- Collision API —
Vector2for shapes,directionon<ray-cast>, andapplyForce/applyImpulse - Animation & Tweening API —
Vector2formarginkeyframes in sprite sheet animations - Filters guide —
Colortype usage on filter nodes - Nodes 2D API — all JSX props that accept
VectorLike