Documentation / @debuffjp/core / Game
Class: Game
Defined in: game.ts:64
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: game.ts:131
Parameters
options
Returns
Game
Properties
background
background:
string
Defined in: game.ts:81
camera
readonlycamera:Camera
Defined in: game.ts:73
canvas
readonlycanvas:HTMLCanvasElement
Defined in: game.ts:65
clock
readonlyclock:FixedClock
Defined in: game.ts:70
draw
readonlydraw:Draw
Defined in: game.ts:67
Immediate-mode drawing API, passed to Scene.render and render hooks.
height
readonlyheight:number
Defined in: game.ts:69
hooks
readonlyhooks:Hooks
Defined in: game.ts:76
Typed lifecycle hooks for plugins and game code.
inspect
readonlyinspect:InspectRegistry
Defined in: game.ts:78
Named JSON snapshot providers for dev tools and scenarios.
lastError
lastError:
GameErrorContext&object|undefined
Defined in: game.ts:215
The error that stopped the loop, if any. Cleared by start().
params
readonlyparams:ParamRegistry
Defined in: game.ts:72
pauseWhenHidden
pauseWhenHidden:
boolean=true
Defined in: game.ts:98
Pause automatically while the tab is hidden.
pixelArt
readonlypixelArt:boolean
Defined in: game.ts:80
random
readonlyrandom:Random
Defined in: game.ts:71
renderScale
renderScale:
number=1
Defined in: game.ts:100
Current backing-store pixels per logical unit (CSS scale × devicePixelRatio).
scaleMode
readonlyscaleMode:ScaleMode
Defined in: game.ts:79
stats
readonlystats:FrameStats
Defined in: game.ts:74
timeScale
timeScale:
number=1
Defined in: game.ts:83
Multiplier on simulation dt; 0.5 = slow motion.
width
readonlywidth:number
Defined in: game.ts:68
Accessors
frozen
Get Signature
get frozen():
boolean
Defined in: game.ts:296
Returns
boolean
isRunning
Get Signature
get isRunning():
boolean
Defined in: game.ts:221
Returns
boolean
plugins
Get Signature
get plugins(): readonly
string[]
Defined in: game.ts:199
Names of installed plugins, in install order.
Returns
readonly string[]
reducedMotion
Get Signature
get reducedMotion():
boolean
Defined in: game.ts:88
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: game.ts:92
Parameters
value
boolean
Returns
void
scene
Get Signature
get scene():
Scene|undefined
Defined in: game.ts:217
Returns
Scene | undefined
Methods
add()
add(
scene):this
Defined in: game.ts:225
Parameters
scene
Returns
this
dispose()
dispose():
void
Defined in: game.ts:204
Stop the loop, run plugin cleanups (reverse order) and detach browser listeners.
Returns
void
emit()
emit(
name,detail?):void
Defined in: game.ts:287
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: game.ts:254
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: game.ts:292
Hit-stop: pause simulation for seconds (rendering continues).
Parameters
seconds
number
Returns
void
go()
go(
id):void
Defined in: game.ts:231
Parameters
id
string
Returns
void
redraw()
redraw():
void
Defined in: game.ts:278
Render the current state again without advancing time or touching frame stats (captures, editors).
Returns
void
resize()
resize():
void
Defined in: game.ts:310
Recompute CSS size and backing-store resolution. Called automatically on container resize and devicePixelRatio changes.
Returns
void
skipSplash()
skipSplash():
void
Defined in: game.ts:184
End the start-up splash now (if it is showing or pending).
Returns
void
start()
start():
void
Defined in: game.ts:241
Returns
void
step()
step(
steps?,draw?):void
Defined in: game.ts:304
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: game.ts:247
Returns
void
toLogical()
readonlytoLogical(clientX,clientY):object
Defined in: game.ts:338
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: game.ts:193
Install a plugin. Throws if the name is invalid or already installed.
Parameters
plugin
Returns
this