import Stage from "./../state/stage.ts"; /** * a State Manager (state machine) */ declare const state: { /** * default state ID for Loading Stage */ LOADING: 0; /** * default state ID for Menu Stage */ MENU: 1; /** * default state ID for "Ready" Stage */ READY: 2; /** * default state ID for Play Stage */ PLAY: 3; /** * default state ID for Game Over Stage */ GAMEOVER: 4; /** * default state ID for Game End Stage */ GAME_END: 5; /** * default state ID for High Score Stage */ SCORE: 6; /** * default state ID for Credits Stage */ CREDITS: 7; /** * default state ID for Settings Stage */ SETTINGS: 8; /** * default state ID for the default Stage * (the default stage is the one running as soon as melonJS is started) */ DEFAULT: 9; /** * default state ID for user defined constants
* @example * const STATE_INFO = state.USER + 0; * const STATE_WARN = state.USER + 1; * const STATE_ERROR = state.USER + 2; * const STATE_CUTSCENE = state.USER + 3; */ USER: 100; /** * Stop the current stage. * @param [shouldPauseTrack=false] - pause current track on screen stop. */ stop(shouldPauseTrack?: boolean): void; /** * pause the current stage * @param [music=false] - pause current music track on screen pause */ pause(music?: boolean): void; /** * Restart the current stage from a full stop. * @param [music=false] - resume current music track on screen resume */ restart(music?: boolean): void; /** * resume the current stage * @param [music=false] - resume current music track on screen resume */ resume(music?: boolean): void; /** * Freeze the current stage for a fixed duration, then automatically resume. * Useful for hit-stop / hit-pause effects on impact. * * Behaviour notes: * - If `freeze()` is called again while a freeze is already active, the * freeze is *extended* to whichever end-time is later (calls do not * stack). The `music` flag from the initial call is preserved. * - If the game was already paused when `freeze()` was called, the freeze * timer will *not* unpause it on expiry — the game stays paused. * - Calling `state.resume()` or `state.stop()` while a freeze is active * cancels the timer and resolves the returned promise immediately. * - The freeze is also cancelled when the window loses focus (BLUR) since * the hit-stop's "moment" is short enough that the user has missed it * by the time they return. The regular `pauseOnBlur` behaviour still * keeps the game paused while away. * - Negative, `NaN`, and `Infinity` durations silently no-op. * @param duration - duration of the freeze in milliseconds * @param [music=false] - also pause the current music track during the freeze * @returns a Promise that resolves once the freeze ends (or is cancelled) * @example * // simple hit-stop on impact * state.freeze(80); * * // chain VFX after the freeze * await state.freeze(120); * spawnImpactParticles(); */ freeze(duration: number, music?: boolean): Promise; /** * return the running state of the state manager * @returns true if a "process is running" */ isRunning(): boolean; /** * Return the pause state of the state manager * @returns true if the game is paused */ isPaused(): boolean; /** * associate the specified state with a Stage * @param stateId - State ID (see constants) * @param stage - Instantiated Stage to associate with state ID * @param [start = false] - if true the state will be changed immediately after adding it. * @example * class MenuScreen extends Stage { * onResetEvent(app) { * // Load background image * app.world.addChild( * new ImageLayer(0, 0, { * image : "bg", * z: 0 // z-index * }) * ); * * // Play music * audio.playTrack("menu"); * } * * onDestroyEvent() { * // Stop music * audio.stopTrack(); * } * } * * state.set(state.MENU, new MenuScreen()); */ set(stateId: number, stage: Stage, start?: boolean): void; /** * returns the stage associated with the specified state * (or the current one if none is specified) * @param [stateId] - State ID (see constants) * @returns the Stage instance associated with the given state ID, or undefined */ get(stateId?: number): Stage | undefined; /** * return a reference to the current stage
* useful to call a object specific method * @returns the current Stage instance, or undefined if no stage is active */ current(): Stage | undefined; /** * specify a global transition effect * @param effect - "fade" for a color fade, "mask" for a shape-based mask transition * @param color - a CSS color value * @param [duration=1000] - expressed in milliseconds * @param [shape] - an Ellipse or Polygon defining the mask shape (required when effect is "mask") * @example * // classic fade to black * state.transition("fade", "#000", 500); * @example * // iris (circle) mask transition * state.transition("mask", "#000", 500, new Ellipse(0, 0, 1, 1)); * @example * // diamond mask transition * state.transition("mask", "#000", 400, new Polygon(0, 0, [ * { x: 0, y: -1 }, { x: 1, y: 0 }, * { x: 0, y: 1 }, { x: -1, y: 0 }, * ])); */ transition(effect: "fade" | "mask", color: string, duration?: number, shape?: import("../geometries/ellipse.ts").Ellipse | import("../geometries/polygon.ts").Polygon): void; /** * enable/disable the transition to a particular state (by default enabled for all) * @param stateId - State ID (see constants) * @param enable - true to enable transition, false to disable */ setTransition(stateId: number, enable: boolean): void; /** * change the game/app state * @param stateId - State ID (see constants) * @param [forceChange=false] - if true the state will be changed immediately (without waiting for the next frame) * @param extraArgs - extra arguments to be passed to the reset functions * @example * // The onResetEvent method on the play screen will receive two args: * // "level_1" and the number 3 * state.change(state.PLAY, false, "level_1", 3); */ change(stateId: number, forceChange?: boolean, ...extraArgs: unknown[]): void; /** * return true if the specified state is the current one * @param stateId - State ID (see constants) * @returns true if the specified state is the current one */ isCurrent(stateId: number): boolean; }; export default state; //# sourceMappingURL=state.d.ts.map