Documentation / @debuffjp/core / Game
Class: Game
Defined in: core/src/game.ts:80
Owns the loop, clock, RNG, params, camera and active scene. Renders with the standard Canvas 2D API; nothing here depends on a third-party renderer.
Constructors
Constructor
new Game(
options):Game
Defined in: core/src/game.ts:173
Parameters
options
Returns
Game
Properties
background
background:
string
Defined in: core/src/game.ts:105
camera
readonlycamera:Camera
Defined in: core/src/game.ts:95
canvas
readonlycanvas:HTMLCanvasElement
Defined in: core/src/game.ts:81
clock
readonlyclock:FixedClock
Defined in: core/src/game.ts:92
draw
readonlydraw:Draw
Defined in: core/src/game.ts:83
Immediate-mode drawing API, passed to Scene.render and render hooks.
hooks
readonlyhooks:Hooks
Defined in: core/src/game.ts:98
Typed lifecycle hooks for plugins and game code.
inspect
readonlyinspect:InspectRegistry
Defined in: core/src/game.ts:100
Named JSON snapshot providers for dev tools and scenarios.
lastError
lastError:
GameErrorContext&object|undefined
Defined in: core/src/game.ts:259
The error that stopped the loop, if any. Cleared by start().
params
readonlyparams:ParamRegistry
Defined in: core/src/game.ts:94
pixelArt
readonlypixelArt:boolean
Defined in: core/src/game.ts:104
pixelSize
readonlypixelSize:number
Defined in: core/src/game.ts:103
CSS pixels per logical unit in scale: "pixel".
random
readonlyrandom:Random
Defined in: core/src/game.ts:93
renderScale
renderScale:
number=1
Defined in: core/src/game.ts:133
Current backing-store pixels per logical unit (CSS scale × devicePixelRatio).
scaleMode
readonlyscaleMode:ScaleMode
Defined in: core/src/game.ts:101
stats
readonlystats:FrameStats
Defined in: core/src/game.ts:96
timeScale
timeScale:
number=1
Defined in: core/src/game.ts:107
Multiplier on simulation dt; 0.5 = slow motion.
Accessors
frozen
Get Signature
get frozen():
boolean
Defined in: core/src/game.ts:419
Returns
boolean
height
Get Signature
get height():
number
Defined in: core/src/game.ts:89
Logical height. Fixed, except in scale: "expand" and "pixel" (see width).
Returns
number
isRunning
Get Signature
get isRunning():
boolean
Defined in: core/src/game.ts:265
Returns
boolean
isStarted
Get Signature
get isStarted():
boolean
Defined in: core/src/game.ts:273
start() was called and stop() hasn't been since. Unlike isRunning, this stays true while the loop is halted for a hidden tab (pauseWhenHidden), and goes false when a loop error stops the game.
Returns
boolean
pauseWhenHidden
Get Signature
get pauseWhenHidden():
boolean
Defined in: core/src/game.ts:122
Pause automatically while the tab is hidden. Turning it off while hidden resumes a started game.
Returns
boolean
Set Signature
set pauseWhenHidden(
value):void
Defined in: core/src/game.ts:126
Parameters
value
boolean
Returns
void
plugins
Get Signature
get plugins(): readonly
string[]
Defined in: core/src/game.ts:243
Names of installed plugins, in install order.
Returns
readonly string[]
reducedMotion
Get Signature
get reducedMotion():
boolean
Defined in: core/src/game.ts:112
True when the player prefers reduced motion. Camera shake is scaled down automatically; read this to tone down your own effects (flashes, screen-wide particles, parallax speed).
Returns
boolean
Set Signature
set reducedMotion(
value):void
Defined in: core/src/game.ts:116
Parameters
value
boolean
Returns
void
scene
Get Signature
get scene():
Scene|undefined
Defined in: core/src/game.ts:261
Returns
Scene | undefined
width
Get Signature
get width():
number
Defined in: core/src/game.ts:85
Logical width. Fixed, except in scale: "expand" and "pixel", where it grows to fill the container (never below the minimum).
Returns
number
Methods
add()
add(
scene):this
Defined in: core/src/game.ts:277
Parameters
scene
Returns
this
dispose()
dispose():
void
Defined in: core/src/game.ts:248
Stop the loop, run plugin cleanups (reverse order) and detach browser listeners.
Returns
void
emit()
emit(
name,detail?):void
Defined in: core/src/game.ts:385
Mark something meaningful that happened: a coin collected, a death, a level cleared. Tests, replays and agents can check for it (the dev tools count events by name, e.g. events.coin in scenarios). Costs one call per listener; nothing listens in production unless you do.
Parameters
name
string
detail?
unknown
Returns
void
frame()
frame(
elapsed,draw?):void
Defined in: core/src/game.ts:348
Advance by real elapsed seconds and render once. Exposed so tests and scenarios can drive the game without requestAnimationFrame.
Parameters
elapsed
number
draw?
boolean = true
Returns
void
freeze()
freeze(
seconds):void
Defined in: core/src/game.ts:415
Hit-stop: pause simulation for seconds (rendering continues).
Parameters
seconds
number
Returns
void
go()
go(
id):void
Defined in: core/src/game.ts:301
Parameters
id
string
Returns
void
redraw()
redraw():
void
Defined in: core/src/game.ts:376
Render the current state again without advancing time or touching frame stats (captures, editors).
Returns
void
resize()
resize():
void
Defined in: core/src/game.ts:433
Recompute CSS size and backing-store resolution. Called automatically on container resize and devicePixelRatio changes.
Returns
void
skipSplash()
skipSplash():
void
Defined in: core/src/game.ts:228
End the start-up splash now (if it is showing or pending).
Returns
void
start()
start():
void
Defined in: core/src/game.ts:328
Returns
void
step()
step(
steps?,draw?):void
Defined in: core/src/game.ts:427
Advance exactly steps simulation steps (deterministic; for scenarios). draw: false skips rendering and frame stats, for fast-forwarding through a replay; call redraw() afterwards.
Parameters
steps?
number = 1
draw?
boolean = true
Returns
void
stop()
stop():
void
Defined in: core/src/game.ts:341
Returns
void
toLogical()
readonlytoLogical(clientX,clientY):object
Defined in: core/src/game.ts:484
Convert client (event) coordinates to logical game coordinates. Bound, so it can be passed around (e.g. to Input).
Parameters
clientX
number
clientY
number
Returns
object
x
x:
number
y
y:
number
use()
use(
plugin):this
Defined in: core/src/game.ts:237
Install a plugin. Throws if the name is invalid or already installed.
Parameters
plugin
Returns
this