import type Camera2d from "./../camera/camera2d.ts";
import World from "../physics/world.js";
import type Renderer from "./../video/renderer.js";
import type { ApplicationSettings, ResolvedApplicationSettings } from "./settings.ts";
/**
* The Application class is the main entry point for creating a melonJS game.
* It initializes the renderer, creates the game world and viewport, registers DOM event
* listeners (resize, orientation, scroll), and starts the game loop.
*
* The Application instance provides access to the core game systems:
* - {@link Application#renderer renderer} — the active Canvas or WebGL renderer
* - {@link Application#world world} — the root container for all game objects
* - {@link Application#viewport viewport} — the default camera / viewport
*
* The app instance is automatically passed to {@link Stage#onResetEvent} and
* {@link Stage#onDestroyEvent}, and is accessible from any renderable via
* {@link Renderable#parentApp parentApp}.
* @category Application
* @example
* // create a new melonJS Application
* const app = new Application(800, 600, {
* parent: "screen",
* scaleMethod: "flex-width",
* renderer: 2, // AUTO
* });
*
* // add objects to the world
* app.world.addChild(new Sprite(0, 0, { image: "player" }));
*
* // access the viewport
* app.viewport.follow(player, app.viewport.AXIS.BOTH);
*/
export default class Application {
/**
* the parent HTML element holding the main canvas of this application
*/
parentElement: HTMLElement;
/**
* a reference to the active Canvas or WebGL renderer
*/
renderer: Renderer;
/**
* the active stage "default" camera
*/
viewport: Camera2d;
/**
* a reference to the game world,
* a world is a virtual environment containing all the game objects
*/
world: World;
/**
* when true, all objects will be added under the root world container.
* When false, a `me.Container` object will be created for each corresponding groups
* @default true
*/
mergeGroup: boolean;
/**
* Last time the game update loop was executed.
* Use this value to implement frame prediction in drawing events,
* for creating smooth motion while running game update logic at
* a lower fps.
*/
lastUpdate: DOMHighResTimeStamp;
/**
* true when this app instance has been initialized
* @default false
*/
isInitialized: boolean;
/**
* the given settings used when creating this application
*/
settings: ResolvedApplicationSettings;
/**
* Specify whether to pause this app when losing focus
* @default true
* @example
* // keep the default game instance running even when losing focus
* app.pauseOnBlur = false;
*/
pauseOnBlur: boolean;
/**
* Specify whether to unpause this app when gaining back focus
* @default true
*/
resumeOnFocus: boolean;
/**
* Specify whether to stop this app when losing focus
* @default false
*/
stopOnBlur: boolean;
isDirty: boolean;
isAlwaysDirty: boolean;
frameCounter: number;
frameRate: number;
accumulator: number;
accumulatorMax: number;
accumulatorUpdateDelta: number;
stepSize: number;
private _onResize?;
private _onOrientationChange?;
private _onScroll?;
updateDelta: number;
lastUpdateStart: number | null;
updateAverageDelta: number;
/**
* Create and initialize a new melonJS Application.
* This is the recommended way to start a melonJS game.
* @param width - The width of the canvas viewport
* @param height - The height of the canvas viewport
* @param options - The optional parameters for the application and default renderer
* @throws {Error} Will throw an exception if it fails to instantiate a renderer
* @example
* const app = new Application(1024, 768, {
* parent: "game-container",
* scale: "auto",
* scaleMethod: "fit",
* renderer: 2, // AUTO
* });
*/
constructor(width: number, height: number, options?: Partial & {
legacy?: boolean;
});
/**
* init the game instance (create a physic world, update starting time, etc..)
* @param width - The width of the canvas viewport
* @param height - The height of the canvas viewport
* @param options - The optional parameters for the application and default renderer
*/
init(width: number, height: number, options?: Partial): void;
/**
* reset the game Object manager
* destroy all current objects
*/
reset(): void;
/**
* Specify the property to be used when sorting renderables for this application game world.
* Accepted values : "x", "y", "z", "depth"
* @see {@link World.sortOn}
*/
get sortOn(): "x" | "y" | "z" | "depth";
set sortOn(value: "x" | "y" | "z" | "depth");
/**
* Fired when a level is fully loaded and all renderable instantiated.
* Additionally the level id will also be passed to the called function.
* @example
* // call myFunction () everytime a level is loaded
* app.onLevelLoaded = this.myFunction.bind(this);
*/
onLevelLoaded(): void;
/**
* Update the renderer framerate using the system config variables.
* @see {@link timer.maxfps}
* @see {@link World.fps}
*/
updateFrameRate(): void;
/**
* Returns the parent HTML Element holding the main canvas of this application
* @returns the parent HTML element
*/
getParentElement(): HTMLElement;
/**
* Returns `true` if the browser/device is currently in fullscreen mode.
* Thin convenience around {@link device.isFullscreen} so the
* fullscreen trio (`isFullscreen` / `requestFullscreen` /
* `exitFullscreen`) lives together on the app instance.
* @category Application
*/
isFullscreen(): boolean;
/**
* Trigger a fullscreen request for this application. Defaults to this
* application's `parentElement` (the container the canvas was appended
* into — see {@link Application#getParentElement}), so the canvas and
* any sibling HUD / overlay markup inside that container go fullscreen
* together.
* @param element - optional element to fullscreen instead of `this.parentElement`
* @example
* // bind F to toggle fullscreen
* me.input.bindKey(me.input.KEY.F, "toggleFullscreen");
* me.event.on(me.event.KEYDOWN, (action) => {
* if (action === "toggleFullscreen") {
* if (!app.isFullscreen()) app.requestFullscreen();
* else app.exitFullscreen();
* }
* });
* @category Application
*/
requestFullscreen(element?: Element): void;
/**
* Exit fullscreen mode for this application.
* @category Application
*/
exitFullscreen(): void;
/**
* The HTML canvas element associated with this application's renderer.
* @example
* // access the canvas DOM element
* const canvas = app.canvas;
*/
get canvas(): HTMLCanvasElement;
/**
* Trigger a manual resize of the application canvas to fit the parent element.
* This is automatically called on window resize/orientation change, but can
* be called manually if the parent element size changes programmatically.
* @example
* // force a resize after changing the parent element dimensions
* app.resize();
*/
resize(): void;
/**
* Destroy this application instance and release all associated resources.
* Removes the canvas from the DOM, destroys the world, and unregisters
* all event listeners.
* @param removeCanvas - if true, the canvas element is removed from the DOM (default: true)
* @example
* // clean up when done
* app.destroy();
*/
destroy(removeCanvas?: boolean): void;
/**
* force the redraw (not update) of all objects
*/
repaint(): void;
/**
* Pause the current stage. Convenience proxy for {@link state.pause}.
* @param [music=false] - also pause the current music track
* @example
* app.pause(); // pause game updates, keep music playing
* app.pause(true); // pause game updates and music
*/
pause(music?: boolean): void;
/**
* Resume the current stage. Convenience proxy for {@link state.resume}.
* @param [music=false] - also resume the current music track
*/
resume(music?: boolean): void;
/**
* Freeze the current stage for a fixed duration, then automatically resume.
* Useful for hit-stop / hit-pause effects on impact.
*
* Convenience proxy for {@link state.freeze}; see that method's
* documentation for the full behaviour matrix (extend-not-stack semantics,
* interaction with manual `state.pause()` / `state.resume()`, automatic
* cancellation on window blur, etc.).
* @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
* app.freeze(80);
*
* // chain VFX after the freeze
* await app.freeze(120);
* spawnImpactParticles();
*/
freeze(duration: number, music?: boolean): Promise;
/** @ignore */
_tick(time: number): void;
/** @ignore */
_onBlur(): void;
/** @ignore */
_onFocus(): void;
/**
* update all objects related to this game active scene/stage
* @param time - current timestamp as provided by the RAF callback
*/
update(time: number): void;
/**
* draw the active scene/stage associated to this game
*/
draw(): void;
}
/**
* The default game application instance.
* Set via {@link setDefaultGame} during engine initialization.
* When using {@link Application} directly, prefer using the app instance
* (e.g. from {@link Stage#onResetEvent} or {@link Renderable#parentApp}).
*/
export declare let game: Application;
/**
* Set the default game application instance.
* @ignore
*/
export declare function setDefaultGame(app: Application): void;
//# sourceMappingURL=application.d.ts.map