Skip to content

Stage

The play area and backdrop behind the sprites. It behaves like a special sprite that cannot move or be cloned, but holds the backdrops and can run its own stage-wide scripts (for example, when the backdrop changes).

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

Stage.answer: string | null

The most recent answer the player typed in response to a question.

Since 1.0.0

Stage.arrayIncludes(array: T[], value: T): boolean

Checks whether a list contains a given value.

Since 1.0.0

Stage.askAndWait(question: string): Yielding<void>

Asks the player a question and pauses the script until they type an answer. In engine code this generator is awaited with yield*; in sprite code the free-function wrapper handles it.

Pauses the script (a generator). In sprite code the free-function wrapper awaits it for you.

Since 1.0.0

Stage.audioEffects: AudioEffectMap

The sound effects (like pitch or pan) currently applied to this sprite or stage’s sounds.

Since 1.0.0

Stage.broadcast(name: string): Promise<void>

Sends a broadcast message and continues without waiting for the receiving scripts to finish.

Since 1.0.0

Stage.broadcastAndWait(name: string): Yielding<void>

Sends a broadcast message and pauses the script until every receiving script has finished. In engine code this generator is awaited with yield*; in sprite code the free-function wrapper handles it.

Pauses the script (a generator). In sprite code the free-function wrapper awaits it for you.

Since 1.0.0

Stage.clearPen(): void

Erases everything that has been drawn on the stage with the pen.

Since 1.0.0

Stage.compare(v1: unknown, v2: unknown): number

Compares two values the way Scratch does, returning a negative, zero, or positive number.

Since 1.0.0

Stage.costume: Costume

The Costume object currently being shown.

Since 1.0.0

Stage.costumeNumber: number

The number of the backdrop currently being shown (1 is the first backdrop).

Since 1.0.0

Stage.degToRad(deg: number): number

Converts an angle in degrees to radians.

Since 1.0.0

Stage.degToScratch(deg: number): number

Converts a standard angle in degrees to Scratch’s direction system.

Since 1.0.0

Stage.effects: _EffectMap

The graphic effects (like color, ghost, or fisheye) currently applied to this sprite or stage.

Since 1.0.0

Stage.fence: {
left: number
right: number
top: number
bottom: number
}

The boundaries of the stage that keep sprites from wandering too far off screen.

Since 1.0.0

Stage.fireBackdropChanged(): Promise<void>

Fires the “when backdrop switches to” triggers for the current backdrop.

Since 1.0.0

Stage.getSound(soundName: string): Sound | undefined

Finds one of this sprite’s sounds by its name or number.

Since 1.0.0

Stage.height: number

The height of the stage in pixels.

Since 1.0.0

Stage.id: UID

A unique identifier for this sprite or stage.

Since 1.0.0

Stage.indexInArray(array: T[], value: T): number

Finds the position of a value within a list.

Since 1.0.0

Stage.itemOf(array: T[], index: number): T | ""

Gets an item from a list by its position.

Since 1.0.0

Stage.keyPressed(name: string): boolean

Checks whether the given key is currently being pressed.

Since 1.0.0

Stage.letterOf(string: string, index: number): string

Gets a single letter from text by its position.

Since 1.0.0

Stage.loudness: number

How loud the microphone input is, from 0 to 100.

Since 1.0.0

Stage.mouse: Mouse

The mouse, used to read the pointer’s position and whether it’s pressed.

Since 1.0.0

Stage.normalizeDeg(deg: number): number

Wraps an angle so it stays within the range of -180 to 180 degrees.

Since 1.0.0

Stage.playSoundUntilDone(soundName: string): Yielding<void>

Plays a sound and pauses the script until that sound finishes. In engine code this generator is awaited with yield*; in sprite code the free-function wrapper handles it.

Pauses the script (a generator). In sprite code the free-function wrapper awaits it for you.

Since 1.0.0

Example

yield* this.playSoundUntilDone("Meow")
Stage.radToDeg(rad: number): number

Converts an angle in radians to degrees.

Since 1.0.0

Stage.radToScratch(rad: number): number

Converts an angle in radians to a Scratch direction.

Since 1.0.0

Stage.random(a: number, b: number): number

Picks a random number between two values (whole numbers if both ends are whole).

Since 1.0.0

Stage.restartTimer(): void

Resets the timer back to zero.

Since 1.0.0

Stage.scratchTan(angle: number): number

Calculates the tangent of an angle in degrees, matching Scratch’s behavior at special angles.

Since 1.0.0

Stage.scratchToDeg(scratchDir: number): number

Converts a Scratch direction to a standard angle in degrees.

Since 1.0.0

Stage.scratchToRad(scratchDir: number): number

Converts a Scratch direction to an angle in radians.

Since 1.0.0

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

All of the sprites in the project, keyed by name.

Since 1.0.0

Stage.stage: Stage

The stage of the project, which all sprites share.

Since 1.0.0

Stage.startSound(soundName: string): Yielding<void>

Starts playing a sound and continues the script right away without waiting for it to finish. In engine code this generator is awaited with yield*; in sprite code the free-function wrapper handles it.

Pauses the script (a generator). In sprite code the free-function wrapper awaits it for you.

Since 1.0.0

Stage.stop(option: StopOption): void

Stops running scripts based on the given option (for example, all scripts or just this one).

Since 1.0.0

Stage.stopAllOfMySounds(): void

Stops only the sounds that this sprite or stage is playing.

Since 1.0.0

Stage.stopAllSounds(): void

Stops every sound playing in the whole project.

Since 1.0.0

Stage.stringIncludes(string: string, substring: string): boolean

Checks whether one piece of text contains another, ignoring upper/lower case.

Since 1.0.0

Stage.timer: number

The number of seconds since the timer was last started or reset.

Since 1.0.0

Stage.toBoolean(value: unknown): boolean

Converts a value into true or false, following Scratch’s rules.

Since 1.0.0

Stage.toNumber(value: unknown): number

Converts a value into a number, treating invalid values as 0.

Since 1.0.0

Stage.toString(value: unknown): string

Converts a value into text.

Since 1.0.0

Stage.triggers: Trigger[]

The list of event triggers (like “when green flag clicked”) attached to this sprite or stage.

Since 1.0.0

Stage.vars: object

The variables belonging to this sprite or stage.

Since 1.0.0

Stage.wait(secs: number): Yielding<void>

Pauses the running script for the given number of seconds. In engine code this generator is awaited with yield*; in sprite code the free-function wrapper handles it.

Pauses the script (a generator). In sprite code the free-function wrapper awaits it for you.

Since 1.0.0

Stage.warp(procedure: GeneratorFunction): (...args: unknown[]) => void

Runs a script all at once without pausing, so it finishes in a single frame.

Since 1.0.0

Stage.watchers: Partial<Record<string, Watcher>>

The variable watchers shown on the stage for this sprite or stage, keyed by name.

Since 1.0.0

Stage.width: number

The width of the stage in pixels.

Since 1.0.0

Stage.wrapClamp(n: number, min: number, max: number): number

Keeps a number within a range, wrapping any extra around to the other end.

Since 1.0.0