Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/tiny-engine/llms.txt
Use this file to discover all available pages before exploring further.
Game is the static entry point for initializing and controlling the tiny-engine runtime. Every game starts by calling Game.setup() to create the canvas and configure the engine, then Game.play() to start the loop. All other engine systems — input, scenes, rendering — are accessible through Game after setup completes.
Game.setup(options)
Creates the canvas element, appends it to the provided root element, initializes the input system, and prepares the scene manager. Must be called before any other Game method.
The logical width of the canvas in pixels. CSS custom property
--width is also set on the root element to this value.The logical height of the canvas in pixels. CSS custom property
--height is also set on the root element.The DOM element that will become the parent of the generated
<canvas>. Typically document.querySelector('#root').An optional
Theme instance that sets the default text style (color, size, font family, weight, and alignment) used by text nodes. If omitted, new Theme() is used, which defaults to 16px sans-serif in black.Optional debug overlays. Pass an object with any combination of the following boolean flags:
| Flag | Default | Description |
|---|---|---|
showColliders | false | Draws collider shapes |
showRayCasts | false | Draws ray cast lines |
showClickables | false | Highlights clickable areas |
Configuration for the
Input system.When
true (the default), calls preventDefault() on every keydown and keyup event, preventing browser shortcuts from firing during gameplay. Set to false to allow shortcuts like Ctrl+R or Ctrl+T to pass through.Game.setup() is idempotent — calling it more than once is a no-op. To reinitialize the engine, call Game.destroy() first.Game.play()
Starts the game loop. Internally schedules the first requestAnimationFrame tick, then runs continuously until paused or destroyed. Scenes can be added either before or after this call.
Game.play() throws an EngineNotSetupError if called before Game.setup(). It also re-starts the loop after a Game.pause() call, making it safe to use as a resume mechanism.
Game.pause()
Pauses the game loop. The current frame finishes rendering, then no further updates occur until Game.play() is called again.
WakeLock, allowing the device screen to sleep.
Game.destroy()
Stops the game loop, removes all event listeners (including the blur/focus listener), destroys the Input instance, and clears the active scene. The engine can be set up again with a fresh Game.setup() call after this.
Game.input
The Input instance, created by Game.setup(). Provides keyboard and pointer query methods and events.
Input API.
Game.sceneManager
The singleton SceneManager instance. Use it to register and switch scenes.
Game.blured
An Event that fires whenever the browser window loses focus. The engine automatically calls Game.pause() and cancels the animation frame before emitting this event, so the loop is already stopped by the time your listener runs.
Auto-pause on blur is built in. You do not need to call
Game.pause() manually in response to Game.blured — the engine has already done so. Call Game.play() to resume.Game.loop(delta)
The internal per-frame method. Clears the canvas, calls start() on the active scene’s root node if it hasn’t started yet, then calls update(), runs the collision system, and calls draw().
Time in seconds elapsed since the previous frame.
Game.loop() is intended for internal use only. Calling it from application code will cause rendering artifacts.Auto-pause on blur
tiny-engine automatically pauses the game when the browser window loses focus. This prevents the game from advancing state while the player cannot see or interact with it. The sequence is:windowfiresblurGame.pause()is called (marks the loop as paused and releases wake lock)- The current animation frame is cancelled
Game.bluredevent is emitted
Game.play() — for example from a “Click to resume” overlay.