← The API

Phaser AE

API docs

v3.0.0-2206 exports in 26 modulesreleased October 19, 2026

ContentsRandom, color and units

Need to get started? Install the Phaser AE CLI →

Content and maths

Random, color and units

The seeded rng (and createRng for code without a game), the one colour parser, toroidal wrapping, shared units

engine/kernel/src/rng.tsengine/kernel/src/color.tsengine/kernel/src/wrap.tsengine/kernel/src/types.ts

Functions

colorRgb

function colorRgb(css: string): [number, number, number]

From @phaser-ae/kernel

Any CSS colour packColor reads, as three floats 0..1 (r, g, b), alpha dropped: what a shader uniform or a vertex colour wants. The one place a pack turns a colour option into floats, so a name, rgb() or hsl() works everywhere.

colorToFloats

function colorToFloats(packed: number, out: Float32Array, o: number): void

From @phaser-ae/kernel

Unpack to four floats 0..1 (r, g, b, a) into out at offset o. For backends filling a uniform or vertex buffer.

packColor

function packColor(css: string): number

From @phaser-ae/kernel

Parse a CSS colour to packed rgba8 (0xRRGGBBAA, unsigned). Accepts ten named colours (white, black, red, green, blue, yellow, cyan, magenta, orange, transparent), #rgb, #rgba, #rrggbb, #rrggbbaa, rgb() / rgba() with 0–255 channels (clamped) and a 0–1 or percentage alpha, and hsl() / hsla() with a hue in degrees, percentages, and a 0–1 or percentage alpha. Case and surrounding space are ignored. Throws on any other form, on a hex digit that is not one, and on an rgb() with a part that is not a number or without three or four parts, so a typo does not silently become black. hsl() is how a ramp is written by hand: hsl(${200 + i * 5}, 45%, 60%).

unpackColor

function unpackColor(packed: number): string

From @phaser-ae/kernel

Packed rgba8 → a CSS hex string: #rrggbb when alpha is 255, else #rrggbbaa.

wrapDelta

function wrapDelta(d: number, size: number): number

From @phaser-ae/kernel

The shortest signed equivalent of a difference d on a circle of size: on a 2000-wide world, 1999 − 1 = 1998 becomes −2. A size of 0 or less returns d.

wrapPos

function wrapPos(v: number, size: number): number

From @phaser-ae/kernel

v brought into [0, size). A size of 0 or less returns v.

Constants

createRng

const createRng: CreateRng

From @phaser-ae/kernel

A seeded stream of its own, for code without a game. See CreateRng.

Types

Cancel

interface Cancel

From @phaser-ae/kernel

Cancels something the kernel gave you: a subscription, a timer, a step, a scene disposer.

  • cancel(): void — Undo it. A second call does nothing.
  • readonly cancelled: boolean — True once cancelled.

Color

type Color = string

From @phaser-ae/kernel

A CSS colour string at the API boundary ('#ff4444', 'red', 'hsl(200, 45%, 60%)'); packed rgba8 inside.

ColumnArray

type ColumnArray = Float32Array | Float64Array | Int32Array | Uint8Array | Uint16Array | Uint32Array

From @phaser-ae/kernel

The typed array behind a column, indexed by roster slot.

Columns

type Columns = Readonly<Record<string, ColumnType>>

From @phaser-ae/kernel

A pack's column declaration: column name → storage type.

ColumnType

type ColumnType = 'f32' | 'i32' | 'u8' | 'u32' | 'rgba8' | 'id'

From @phaser-ae/kernel

Column storage types a pack may declare in its columns. rgba8 reads and writes as a CSS colour; id is a u32.

CreateRng

type CreateRng = (seedOrWords: number | number[]) => Rng

From @phaser-ae/kernel

A seeded stream of its own, for code without a game: a pack's pure rules, a level generator, a worker job. The same seed gives the same draws, here and in game.rng. Inside a game, use game.rng (or game.rng.fork(label)) instead, so one seed replays everything.

Given four words instead of a seed (an array snapshot() returned, kept in plain state), the stream lives in that array: every draw advances it in place, so rules whose state is plain JSON carry their randomness in it with no save code of their own. const s = { rng: [...createRng(seed).snapshot()] }; createRng(s.rng).int(1, 6);

Id

type Id = string & { readonly __id: unique symbol }

From @phaser-ae/kernel

Stable, human-legible, kernel-suffixed object id: enemy-crab-7. Never reused.

LayerName

type LayerName = string

From @phaser-ae/kernel

A layer name declared by a composed world pack, e.g. 'floor' | 'world' | 'fx'.

PackId

type PackId = string

From @phaser-ae/kernel

A pack's id as published: lighting-2d.

Radians

type Radians = number

From @phaser-ae/kernel

Radians. Never degrees in an API.

Rng

interface Rng

From @phaser-ae/kernel

The seeded random source: all chance in a game flows from here, never from Math.random, so the same seed and the same steps replay the same game. xoshiro128** seeded by splitmix32.

A game has one, game.rng (a pack's k.rng). Code that has no game, such as a pack's pure rules or a level generator in a worker, makes its own with createRng(seed) from @phaser-ae/kernel. Never write another generator.

  • readonly seed: number — The seed this stream started from, as an unsigned 32-bit integer.
  • next(): number — A float in [0, 1).
  • between(min: number, max: number): number — A float in [min, max).
  • int(min: number, maxInclusive: number): number — An integer in [min, maxInclusive].
  • chance(probability: number): boolean — True with the given probability, 0..1.
  • pick<T>(items: ReadonlyArray<T>): T — One item, uniformly. Throws rng.pick: empty on an empty array.
  • weighted<T>(items: ReadonlyArray<readonly [T, number]>): T — One item, by [item, weight] pairs; weights need not sum to 1. An empty list throws.
  • shuffle<T>(items: T[]): T[] — Shuffle items in place (Fisher–Yates) and return the same array.
  • fork(label: string): Rng — A child stream for one purpose (a level generator, a procgen job), seeded from this stream's seed and label. Drawing from it never disturbs this stream, and the same seed and label always give the same child, however far this stream has advanced.
  • snapshot(): RngState — Where this stream stands, to put in a save or a snapshot. restore returns the stream to exactly here, so the draws after it repeat. Cheap: four numbers.
  • restore(state: RngState): void — Return to a point snapshot gave, of this stream or of any stream: the draws after it are the same as they were after that snapshot. Throws rng.restore: not a state on anything else, so a corrupt save fails loudly.

RngState

type RngState = readonly [number, number, number, number]

From @phaser-ae/kernel

Where a stream stands: xoshiro128**'s four 32-bit words. Plain numbers, so it goes into a JSON save as it is. Only Rng.restore gives it meaning; never build one by hand.

Seconds

type Seconds = number

From @phaser-ae/kernel

Seconds, as a float. Never milliseconds.

Transform

interface Transform

From @phaser-ae/kernel

The kernel's transform columns. 2D worlds ignore z, pitch, roll and sz; 3D worlds use them.

  • x: number — Centre x, world units.
  • y: number — Centre y, world units.
  • z: number — z, world units; 3D worlds.
  • rot: Radians — Rotation in radians: the turn on screen in 2D, the yaw about y in 3D.
  • sx: number — Scale x.
  • sy: number — Scale y.
  • pitch: Radians — Pitch in radians about x; 3D worlds. 2D worlds leave it 0.
  • roll: Radians — Roll in radians about z; 3D worlds. 2D worlds leave it 0.
  • sz: number — Scale z; 3D worlds. 2D worlds leave it 1.

Wrap

interface Wrap

From @phaser-ae/kernel

The world's period in world units: positions live in [0, w) × [0, h).

  • readonly w: number — Width of the torus, world units.
  • readonly h: number — Height of the torus, world units.