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.
answer
Section titled “answer”Project.answer: string | nullThe most recent text the player typed in response to an “ask” question, or null if none yet.
Since 1.0.0
askAndWait
Section titled “askAndWait”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?");attach
Section titled “attach”Project.attach(renderTarget: string | HTMLElement): voidConnects the project to a page element so it can be shown and clicked on.
Since 1.0.0
changeSpriteLayer
Section titled “changeSpriteLayer”Project.changeSpriteLayer(sprite: Sprite, layerDelta: number, relativeToSprite?: Sprite): voidMoves a sprite forward or backward through the drawing layers.
Since 1.0.0
fireTrigger
Section titled “fireTrigger”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);gameEffect
Section titled “gameEffect”Project.gameEffect: GameEffectThe engine that schedules and runs all of the project’s scripts and visual effects.
Since 1.0.0
getTargetById
Section titled “getTargetById”Project.getTargetById(id: UID): Sprite | Stage | nullLooks up a sprite, clone, or the stage by its unique id.
Since 1.0.0
getTriggerGenerators
Section titled “getTriggerGenerators”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
greenFlag
Section titled “greenFlag”Project.greenFlag(): voidStarts the project just like clicking the green flag does.
Since 1.0.0
Example
project.greenFlag();Project.input: InputTracks keyboard and mouse input from the person playing the project.
Since 1.0.0
loudness
Section titled “loudness”Project.loudness: numberHow loud the microphone currently is, from 0 (silent) to 100 (very loud).
Since 1.0.0
registerTarget
Section titled “registerTarget”Project.registerTarget(target: Sprite | Stage): voidAdds a sprite, clone, or the stage to the lookup table so it can be found by id.
Since 1.0.0
renderer
Section titled “renderer”Project.renderer: RendererThe renderer that draws the stage and sprites to the screen.
Since 1.0.0
restartTimer
Section titled “restartTimer”Project.restartTimer(): voidResets the project timer back to zero.
Since 1.0.0
runningTriggers
Section titled “runningTriggers”Project.runningTriggers: TriggerWithTarget[]The list of triggers (scripts) that are currently running in the project.
Since 1.0.0
sprites
Section titled “sprites”Project.sprites: Partial<Record<string, Sprite>>All of the project’s sprites, looked up by name.
Since 1.0.0
spritesAndClones
Section titled “spritesAndClones”Project.spritesAndClones: Sprite[]Every sprite together with all of its clones, in drawing order.
Since 1.0.0
spritesAndStage
Section titled “spritesAndStage”Project.spritesAndStage: (Sprite | Stage)[]Every sprite and clone plus the stage, all together in one list.
Since 1.0.0
Project.stage: StageThe single Stage backdrop target that every sprite is drawn on top of.
Since 1.0.0
Project.stop(option: StopOption): voidStops running scripts according to the given stop option.
Since 1.0.0
stopAll
Section titled “stopAll”Project.stopAll(): voidStops every running script, clears all clones, resets effects, and restarts the timer.
Since 1.0.0
stopAllSounds
Section titled “stopAllSounds”Project.stopAllSounds(): voidStops every sound that any sprite or the stage is currently playing.
Since 1.0.0
stopByTarget
Section titled “stopByTarget”Project.stopByTarget(targetID: UID): voidStops all running scripts that belong to one specific sprite or clone.
Since 1.0.0
Project.timer: numberThe number of seconds that have passed since the timer was last started.
Since 1.0.0
unregisterTarget
Section titled “unregisterTarget”Project.unregisterTarget(id: UID): voidRemoves a target from the lookup table so it can no longer be found by id.
Since 1.0.0