BLIT386BLIT386

Core Types

The integer core types: Vector2i, Rect2i, and Color32.

The integer-coordinate primitives shared across the engine: Vector2i, Rect2i, and Color32.

Vector2i

Vector2i Since 0.1.0

Integer 2D vector. Constructor auto-truncates floats toward zero. Used for all positions, sizes, and camera offsets.

const  = new (10, 20);
.;
.; // direct access
.;
.; // aliases for x / y (useful when treating the vector as a size)

// Static factories
.(); // (0, 0) - cached frozen singleton
.(); // (1, 1) - cached frozen singleton
.(); // (0, -1)
.(); // (0, 1)
.(); // (-1, 0)
.(); // (1, 0)
.(, ); // truncate floats → integer vector

// Math utilities
.(, ); // Euclidean distance (float)
.(, ); // squared distance (avoids sqrt)
.(, ); // scalar dot product
.(, , ); // interpolate, t clamped [0,1], result truncated
.(, , , ); // zero-allocation lerp into existing vector

Instance methods: .add(), .sub(), .mul(), .dot(), .clone(), .isEqual(other), .isEqualXY(x, y), .isZero(), .negate(), .abs(), .min(), .max(), etc. See src/utils/Vector2i.ts for the full list.

Rect2i

Rect2i Since 0.1.0

Integer rectangle with x, y, width, height fields.

const  = new (, , , );

// Static factories
.(); // (0,0,0,0) - cached frozen singleton
.(, ); // from corner vectors
.(, , , ); // zero-allocation variant
.(, ); // centered rectangle
.(, , , ); // zero-allocation variant
.(, , ); // one cell of a grid of equal tiles

// Instance methods
.(); // boolean - point inside rect
.(, ); // boolean - raw coordinates, no Vector2i alloc
.(); // boolean - rects overlap
.(); // boolean - same position and size
.(); // Rect2i | null - overlap area
.(, ); // boolean - write overlap into out when it exists
.; // Vector2i getter
.; // Vector2i getter (top-left)
.; // Vector2i getter (bottom-right)

Rect2i.fromTile(col, row, tileSize) builds one cell of a grid of equal tiles; tileSize is a number or a Vector2i. It validates its arguments (a RangeError for a size that is not a whole number from 1 to 8192, or a negative or fractional col / row) but does not check against any image (sheet.tileRect does that).

Color32

Color32 Since 0.1.0

32-bit RGBA color (channels 0-255).

const  = new (, , , );

// Cached color constants (static getters; frozen singletons)
.;
.;
.;
.;
.;
.;
.;
.;
.;
.(); // grayscale, value 0-255

// Hex parsing
.('#ff8800'); // returns Color32

// Named color registry (global, case-insensitive)
.('brand', new (255, 128, 0, 255));
.('brand'); // → Color32 | undefined
.('brand', );
.('brand');

// Interpolation
.(, , ); // blend a→b; t clamped [0,1]; RGBA independent; truncates like instance lerp
.(, ); // same semantics as static helper

// Conversion
.(); // [r/255, g/255, b/255, a/255]
.; // perceived brightness: 0.299r + 0.587g + 0.114b
.(); // '#rrggbb' string
.(); // boolean - all RGBA channels match

// Linear light (real sRGB piecewise transfer, not a 2.2 power)
.(); // encoded sRGB → linear light; alpha untouched
.(); // linear light → encoded sRGB
.(); // same, mutating; returns this
.();

Linear light

Color math that models light - exposure, additive glow, physically sensible blending - belongs in linear space, not in the encoded values a palette stores. toLinear and toSrgb convert between the two using the real sRGB piecewise transfer function, including the straight toe below the 0.04045 breakpoint. A bare 2.2 power is close enough in the midtones and an order of magnitude wrong near black, which is exactly where a fade spends its most visible frames.

8-bit precision

Channels stay 8-bit, so a round trip through linear light is exact in the upper half of the range and drifts by up to about eight levels near black. Convert, do the math, convert back - do not use linear light as a storage format.

BT.paletteFadeExposure is these helpers applied to a whole palette; see Palette.

API history

SymbolSinceLast changedStatus
Color320.1.0–stable
Rect2i0.1.0–stable
Vector2i0.1.0–stable

0.1.0 - Sat Dec 13 2025

  • AddedColor32
  • AddedRect2i
  • AddedVector2i

See also

Last updated on October 18, 2026

On this page