Skip to content

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 ​

ts
new Stage(app, textures): Stage;

Defined in: src/core/Stage.ts:44

Parameters ​

ParameterType
appApplication
texturesTextureRegistry

Returns ​

Stage

Properties ​

add ​

ts
readonly add: ObjectFactory;

Defined in: src/core/Stage.ts:20


app ​

ts
readonly app: Application;

Defined in: src/core/Stage.ts:45


cameras ​

ts
readonly cameras: object;

Defined in: src/core/Stage.ts:23

main ​

ts
main: Camera;

input ​

ts
readonly input: object;

Defined in: src/core/Stage.ts:24

activePointer ​

ts
activePointer: Pointer;

pixelDensity ​

ts
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 ​

ts
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 ​

ts
readonly screen: Container<ContainerChild>;

Defined in: src/core/Stage.ts:19


textures ​

ts
readonly textures: TextureRegistry;

Defined in: src/core/Stage.ts:46


time ​

ts
readonly time: Clock;

Defined in: src/core/Stage.ts:22


tweens ​

ts
readonly tweens: Tweener;

Defined in: src/core/Stage.ts:21


world ​

ts
readonly world: Container<ContainerChild>;

Defined in: src/core/Stage.ts:18


onCaught ​

ts
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 ​

ts
get fps(): number;

Defined in: src/core/Stage.ts:65

Returns ​

number


height ​

Get Signature ​

ts
get height(): number;

Defined in: src/core/Stage.ts:61

Returns ​

number


width ​

Get Signature ​

ts
get width(): number;

Defined in: src/core/Stage.ts:57

Returns ​

number

Methods ​

caught() ​

ts
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 ​

ParameterType
stepstring
errunknown

Returns ​

void


destroy() ​

ts
destroy(): void;

Defined in: src/core/Stage.ts:138

Returns ​

void


frame() ​

ts
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 ​

ParameterType
deltanumber

Returns ​

void


guard() ​

ts
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 ​

ParameterType
stepstring
fn() => void

Returns ​

void


guarded() ​

ts
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 ​

ParameterType
stepstring
fn() => T
fallbackT

Returns ​

T


keepSharp() ​

ts
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 ​

ParameterType
objContainer

Returns ​

void


onResize() ​

ts
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 ​

ParameterType
fn() => void

Returns ​

() => void


update() ​

ts
abstract update(now, delta): void;

Defined in: src/core/Stage.ts:78

Parameters ​

ParameterType
nownumber
deltanumber

Returns ​

void

Released under the MIT License.