1681-engine / index / Stage
Abstract Class: Stage ​
Defined in: src/core/Stage.ts:14
What a world object is created in: a world layer the camera moves (children sorted by depth), a screen layer above it, and the per-frame services (tweens, timers, camera, pointer). Subclasses implement update.
Constructors ​
Constructor ​
new Stage(app, textures): Stage;Defined in: src/core/Stage.ts:44
Parameters ​
| Parameter | Type |
|---|---|
app | Application |
textures | TextureRegistry |
Returns ​
Stage
Properties ​
add ​
readonly add: ObjectFactory;Defined in: src/core/Stage.ts:20
app ​
readonly app: Application;Defined in: src/core/Stage.ts:45
cameras ​
readonly cameras: object;Defined in: src/core/Stage.ts:23
main ​
main: Camera;input ​
readonly input: object;Defined in: src/core/Stage.ts:24
activePointer ​
activePointer: Pointer;pixelDensity ​
pixelDensity: number = 1;Defined in: src/core/Stage.ts:36
Texels of the pixel-perfect grid to a world pixel (whole, 1 by default). A game whose characters are drawn finer than its world pixel (two art pixels to one) sets 2, so the grid keeps their detail; everything else still lands on that finer grid.
pixelPerfect ​
pixelPerfect: boolean = false;Defined in: src/core/Stage.ts:30
Pixel-perfect: the world drawn one texel to a world pixel and scaled up by the camera's zoom (PixelGrid), so turned, scaled and between-pixels art lands on one grid; text made by add.text/add.label stays at screen resolution. Off (the default), the world is drawn straight at the zoom. Takes effect on the next frame; may be switched any time.
screen ​
readonly screen: Container<ContainerChild>;Defined in: src/core/Stage.ts:19
textures ​
readonly textures: TextureRegistry;Defined in: src/core/Stage.ts:46
time ​
readonly time: Clock;Defined in: src/core/Stage.ts:22
tweens ​
readonly tweens: Tweener;Defined in: src/core/Stage.ts:21
world ​
readonly world: Container<ContainerChild>;Defined in: src/core/Stage.ts:18
onCaught ​
static onCaught: ((where, err) => void) | null = null;Defined in: src/core/Stage.ts:16
Told of every fault a guarded step caught (error telemetry, if the game sets one).
Accessors ​
fps ​
Get Signature ​
get fps(): number;Defined in: src/core/Stage.ts:65
Returns ​
number
height ​
Get Signature ​
get height(): number;Defined in: src/core/Stage.ts:61
Returns ​
number
width ​
Get Signature ​
get width(): number;Defined in: src/core/Stage.ts:57
Returns ​
number
Methods ​
caught() ​
protected caught(step, err): void;Defined in: src/core/Stage.ts:129
What a guarded step threw: logged once per distinct error, or a fault repeating every frame floods the log at 60 a second.
Parameters ​
| Parameter | Type |
|---|---|
step | string |
err | unknown |
Returns ​
void
destroy() ​
destroy(): void;Defined in: src/core/Stage.ts:138
Returns ​
void
frame() ​
frame(delta): void;Defined in: src/core/Stage.ts:85
One frame: game logic, then tweens and timers, then the camera. Pixi renders after. Each step is guarded: a ticker listener that throws never asks for the next animation frame, so one bad frame used to stop the world for good — the canvas frozen and no input reaching the server (seen on Android).
Parameters ​
| Parameter | Type |
|---|---|
delta | number |
Returns ​
void
guard() ​
protected guard(step, fn): void;Defined in: src/core/Stage.ts:114
Runs one step of a frame and swallows what it throws, so the steps after it still run. Subclasses guard the parts of their own update too: a fault before the camera follows the player used to leave the view standing on one spot while the world went on.
Parameters ​
| Parameter | Type |
|---|---|
step | string |
fn | () => void |
Returns ​
void
guarded() ​
protected guarded<T>(
step,
fn,
fallback
): T;Defined in: src/core/Stage.ts:119
guard for a step that answers something: fallback when it threw.
Type Parameters ​
| Type Parameter |
|---|
T |
Parameters ​
| Parameter | Type |
|---|---|
step | string |
fn | () => T |
fallback | T |
Returns ​
T
keepSharp() ​
keepSharp(obj): void;Defined in: src/core/Stage.ts:103
Keeps a piece of text made outside add.text/add.label (put on the world any way) at screen resolution while the world is pixel-perfect. Those two do it themselves.
Parameters ​
| Parameter | Type |
|---|---|
obj | Container |
Returns ​
void
onResize() ​
onResize(fn): () => void;Defined in: src/core/Stage.ts:70
Calls fn whenever the window changes size; the returned function stops it (a per-map listener must).
Parameters ​
| Parameter | Type |
|---|---|
fn | () => void |
Returns ​
() => void
update() ​
abstract update(now, delta): void;Defined in: src/core/Stage.ts:78
Parameters ​
| Parameter | Type |
|---|---|
now | number |
delta | number |
Returns ​
void