Skip to content

Project

The whole game: the stage, every sprite, and the event loop that runs their scripts each frame. You create one Project to start a game and it coordinates input, rendering, and which triggers fire.

The Project engine class. Most members are available as free functions; this page documents the underlying API for advanced use.

Project.answer: string | null

The most recent text the player typed in response to an “ask” question, or null if none yet.

Since 1.0.0

Project.askAndWait(question: string): Promise<void>

Shows a question on screen and waits for the player to type an answer.

Since 1.0.0

Example

await project.askAndWait("What's your name?");
Project.attach(renderTarget: string | HTMLElement): void

Connects the project to a page element so it can be shown and clicked on.

Since 1.0.0

Project.changeSpriteLayer(sprite: Sprite, layerDelta: number, relativeToSprite?: Sprite): void

Moves a sprite forward or backward through the drawing layers.

Since 1.0.0

Project.fireTrigger(trigger: symbol, options?: TriggerOptions): Promise<void>

Triggers an event so any matching scripts start running.

Since 1.0.0

Example

void project.fireTrigger(Trigger.GREEN_FLAG);
Project.gameEffect: GameEffect

The engine that schedules and runs all of the project’s scripts and visual effects.

Since 1.0.0

Project.getTargetById(id: UID): Sprite | Stage | null

Looks up a sprite, clone, or the stage by its unique id.

Since 1.0.0

Project.getTriggerGenerators(trigger: symbol, options?: TriggerOptions): { generator: Generator; targetID: UID }[]

Finds and prepares all scripts that should run for a given trigger event.

Since 1.0.0

Project.greenFlag(): void

Starts the project just like clicking the green flag does.

Since 1.0.0

Example

project.greenFlag();
Project.input: Input

Tracks keyboard and mouse input from the person playing the project.

Since 1.0.0

Project.loudness: number

How loud the microphone currently is, from 0 (silent) to 100 (very loud).

Since 1.0.0

Project.registerTarget(target: Sprite | Stage): void

Adds a sprite, clone, or the stage to the lookup table so it can be found by id.

Since 1.0.0

Project.renderer: Renderer

The renderer that draws the stage and sprites to the screen.

Since 1.0.0

Project.restartTimer(): void

Resets the project timer back to zero.

Since 1.0.0

Project.runningTriggers: TriggerWithTarget[]

The list of triggers (scripts) that are currently running in the project.

Since 1.0.0

Project.sprites: Partial<Record<string, Sprite>>

All of the project’s sprites, looked up by name.

Since 1.0.0

Project.spritesAndClones: Sprite[]

Every sprite together with all of its clones, in drawing order.

Since 1.0.0

Project.spritesAndStage: (Sprite | Stage)[]

Every sprite and clone plus the stage, all together in one list.

Since 1.0.0

Project.stage: Stage

The single Stage backdrop target that every sprite is drawn on top of.

Since 1.0.0

Project.stop(option: StopOption): void

Stops running scripts according to the given stop option.

Since 1.0.0

Project.stopAll(): void

Stops every running script, clears all clones, resets effects, and restarts the timer.

Since 1.0.0

Project.stopAllSounds(): void

Stops every sound that any sprite or the stage is currently playing.

Since 1.0.0

Project.stopByTarget(targetID: UID): void

Stops all running scripts that belong to one specific sprite or clone.

Since 1.0.0

Project.timer: number

The number of seconds that have passed since the timer was last started.

Since 1.0.0

Project.unregisterTarget(id: UID): void

Removes a target from the lookup table so it can no longer be found by id.

Since 1.0.0