minimojs 1.0.0-alpha.3 → 1.0.0-alpha.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +87 -284
  2. package/dist/internal/AnimationSystem.js +345 -0
  3. package/dist/internal/AssetSystem.d.ts +6 -0
  4. package/dist/internal/AssetSystem.js +273 -0
  5. package/dist/internal/BackgroundSystem.d.ts +1 -0
  6. package/dist/internal/BackgroundSystem.js +26 -0
  7. package/dist/internal/CanvasSystem.d.ts +1 -0
  8. package/dist/internal/CanvasSystem.js +51 -0
  9. package/dist/internal/DesignNamingCheck.d.ts +1 -0
  10. package/dist/internal/DesignNamingCheck.js +7 -0
  11. package/dist/internal/ExplosionSystem.d.ts +1 -0
  12. package/dist/internal/ExplosionSystem.js +540 -0
  13. package/dist/internal/InputSystem.d.ts +1 -0
  14. package/dist/internal/InputSystem.js +292 -0
  15. package/dist/internal/LoopSystem.d.ts +1 -0
  16. package/dist/internal/LoopSystem.js +61 -0
  17. package/dist/internal/PhysicsSystem.d.ts +1 -0
  18. package/dist/internal/PhysicsSystem.js +174 -0
  19. package/dist/internal/RenderSystem.d.ts +1 -0
  20. package/dist/internal/RenderSystem.js +1021 -0
  21. package/dist/internal/SoundSystem.d.ts +39 -0
  22. package/dist/internal/SoundSystem.js +292 -0
  23. package/dist/internal/SpriteSystem.d.ts +1 -0
  24. package/dist/internal/SpriteSystem.js +32 -0
  25. package/dist/internal/TextSystem.d.ts +1 -0
  26. package/dist/internal/TextSystem.js +16 -0
  27. package/dist/internal/TimerSystem.d.ts +1 -0
  28. package/dist/internal/TimerSystem.js +43 -0
  29. package/dist/internal/TrailSystem.d.ts +1 -0
  30. package/dist/internal/TrailSystem.js +116 -0
  31. package/dist/internal/TransitionSystem.d.ts +1 -0
  32. package/dist/internal/TransitionSystem.js +74 -0
  33. package/dist/internal/arcade-racer/ArcadeRacerCollisionSystem.d.ts +1 -0
  34. package/dist/internal/arcade-racer/ArcadeRacerCollisionSystem.js +198 -0
  35. package/dist/internal/arcade-racer/ArcadeRacerLaneSystem.d.ts +1 -0
  36. package/dist/internal/arcade-racer/ArcadeRacerLaneSystem.js +120 -0
  37. package/dist/internal/arcade-racer/ArcadeRacerRenderSystem.d.ts +1 -0
  38. package/dist/internal/arcade-racer/ArcadeRacerRenderSystem.js +599 -0
  39. package/dist/internal/arcade-racer/ArcadeRacerRoadSprite.d.ts +1 -0
  40. package/dist/internal/arcade-racer/ArcadeRacerRoadSprite.js +13 -0
  41. package/dist/internal/arcade-racer/ArcadeRacerTrackSystem.d.ts +1 -0
  42. package/dist/internal/arcade-racer/ArcadeRacerTrackSystem.js +447 -0
  43. package/dist/minimo-ambient.d.ts +299 -0
  44. package/dist/minimo-ambient.js +1445 -0
  45. package/dist/minimo-arcaderacer.d.ts +1431 -0
  46. package/dist/minimo-arcaderacer.js +2060 -0
  47. package/dist/minimo-cards.d.ts +359 -0
  48. package/dist/minimo-cards.js +819 -0
  49. package/dist/minimo-format.d.ts +429 -0
  50. package/dist/minimo-format.js +447 -0
  51. package/dist/minimo.d.ts +1815 -209
  52. package/dist/minimo.js +2660 -783
  53. package/package.json +10 -3
  54. package/dist/animations.js +0 -30
  55. package/dist/audio.js +0 -17
  56. package/dist/game.js +0 -1105
  57. package/dist/input.js +0 -185
  58. package/dist/internal-types.js +0 -4
  59. package/dist/physics.js +0 -10
  60. package/dist/render.js +0 -75
  61. package/dist/sprite.js +0 -149
  62. package/dist/timers.js +0 -23
  63. /package/dist/{pointer-info.js → internal/AnimationSystem.d.ts} +0 -0
package/dist/minimo.d.ts CHANGED
@@ -7,54 +7,253 @@
7
7
  * ALL ROTATIONS ARE IN DEGREES.
8
8
  * THE ENGINE LOOP USES requestAnimationFrame ONLY.
9
9
  */
10
+ import { SoundPlayback } from "./internal/SoundSystem.js";
11
+ import type { PlaySoundOptions } from "./internal/SoundSystem.js";
12
+ import type { DesignObject } from "./minimo-format.js";
13
+ export { Design, parseAssetFile } from "./minimo-format.js";
14
+ export { SoundPlayback } from "./internal/SoundSystem.js";
15
+ export type { PlaySoundOptions, SoundPlaybackState } from "./internal/SoundSystem.js";
16
+ export type { AssetFile, DesignBackground, DesignEmoji, DesignFile, DesignImage, DesignObject, DesignObjectBase, DesignObjectType, DesignSpriteBase, DesignText, ImageAsset, SoundAsset, UnknownAsset, } from "./minimo-format.js";
10
17
  /**
11
- * A 2D game object rendered as an emoji on the canvas.
18
+ * Optional tuning values for {@link Game.animateExplode}.
12
19
  *
13
- * Instantiate directly or extend to create custom sprite types.
14
- * Register with the engine by passing the instance to {@link Game.add}.
20
+ * All fields are optional. Omitted fields use the engine defaults.
21
+ */
22
+ export interface ExplodeOptions {
23
+ /** Number of vertical slices used to break the sprite apart. */
24
+ rows?: number;
25
+ /** Number of horizontal slices used to break the sprite apart. */
26
+ cols?: number;
27
+ /** Total effect duration in **milliseconds**. */
28
+ durationMs?: number;
29
+ /** Initial outward velocity magnitude in pixels per second. */
30
+ speed?: number;
31
+ /** Downward acceleration applied to pieces in pixels per second squared. */
32
+ gravityY?: number;
33
+ /** Maximum angular speed applied to pieces, in degrees per second. */
34
+ spin?: number;
35
+ /** Whether pieces fade out as the effect approaches completion. */
36
+ fade?: boolean;
37
+ /** Whether the original sprite is destroyed instead of restored after the effect. */
38
+ destroySprite?: boolean;
39
+ }
40
+ /**
41
+ * Cardinal flow direction used by directional visual effects.
42
+ */
43
+ export type FlowDirection = "left-to-right" | "right-to-left" | "top-to-bottom" | "bottom-to-top";
44
+ /**
45
+ * Direction used by piece-based local integration and disintegration effects.
15
46
  *
16
- * **Coordinate system:** center-based world space. `(x, y)` is the center of
17
- * the sprite. Positive X = right, positive Y = down.
47
+ * - Cardinal values apply a directional sweep across the sprite.
48
+ * - `"in-place"` keeps pieces in their final positions and only randomizes
49
+ * when each piece appears or disappears.
50
+ */
51
+ export type PieceFlowDirection = FlowDirection | "in-place";
52
+ /**
53
+ * Optional tuning values for {@link Game.animateAssemble}.
18
54
  *
19
- * **Lifecycle:** A sprite exists until {@link Game.destroySprite} is called or
20
- * {@link Game.reset} is invoked. After destruction, do not read or write its fields.
55
+ * All fields are optional. Omitted fields use the engine defaults.
56
+ */
57
+ export interface AssembleOptions {
58
+ /** Number of vertical slices used to reconstruct the sprite. */
59
+ rows?: number;
60
+ /** Number of horizontal slices used to reconstruct the sprite. */
61
+ cols?: number;
62
+ /** Total effect duration in **milliseconds**. */
63
+ durationMs?: number;
64
+ /** Initial outward distance magnitude in pixels per second equivalent. */
65
+ speed?: number;
66
+ /** Downward pull applied while pieces converge, in pixels per second squared. */
67
+ gravityY?: number;
68
+ /** Maximum angular speed applied to pieces, in degrees per second. */
69
+ spin?: number;
70
+ /** Whether pieces fade in while assembling. */
71
+ fade?: boolean;
72
+ }
73
+ /**
74
+ * Optional tuning values for {@link Game.animateDisintegrate}.
21
75
  *
22
- * @example
23
- * ```ts
24
- * // Direct instantiation
25
- * const coin = new Sprite("🪙");
26
- * coin.x = 300;
27
- * coin.y = 200;
28
- * coin.size = 32;
29
- * game.add(coin);
30
- * ```
76
+ * All fields are optional. Omitted fields use the engine defaults.
77
+ */
78
+ export interface DisintegrateOptions {
79
+ /** Number of vertical slices used to dissolve the sprite. */
80
+ rows?: number;
81
+ /** Number of horizontal slices used to dissolve the sprite. */
82
+ cols?: number;
83
+ /** Total effect duration in **milliseconds**. */
84
+ durationMs?: number;
85
+ /** Primary sweep direction across the sprite. */
86
+ direction?: PieceFlowDirection;
87
+ /** Maximum local travel distance in pixels for each piece. */
88
+ distance?: number;
89
+ /** Maximum angular speed applied to pieces, in degrees per second. */
90
+ spin?: number;
91
+ /** Whether pieces fade out as they disintegrate. */
92
+ fade?: boolean;
93
+ /** Whether the original sprite is destroyed instead of left hidden after the effect. */
94
+ destroySprite?: boolean;
95
+ }
96
+ /**
97
+ * Optional tuning values for {@link Game.animateIntegrate}.
31
98
  *
32
- * @example
33
- * ```ts
34
- * // Subclassing for custom game objects
35
- * class Player extends Sprite {
36
- * health = 3;
37
- *
38
- * constructor(x: number, y: number) {
39
- * super("🐢");
40
- * this.x = x;
41
- * this.y = y;
42
- * this.size = 48;
43
- * this.gravityScale = 1;
44
- * }
45
- * }
99
+ * All fields are optional. Omitted fields use the engine defaults.
100
+ */
101
+ export interface IntegrateOptions {
102
+ /** Number of vertical slices used to reconstruct the sprite. */
103
+ rows?: number;
104
+ /** Number of horizontal slices used to reconstruct the sprite. */
105
+ cols?: number;
106
+ /** Total effect duration in **milliseconds**. */
107
+ durationMs?: number;
108
+ /** Primary sweep direction across the sprite. */
109
+ direction?: PieceFlowDirection;
110
+ /** Maximum local travel distance in pixels for each piece. */
111
+ distance?: number;
112
+ /** Maximum angular speed applied to pieces, in degrees per second. */
113
+ spin?: number;
114
+ /** Whether pieces fade in while integrating. */
115
+ fade?: boolean;
116
+ }
117
+ /**
118
+ * Wipe mode used by {@link Game.animateWipe}.
119
+ */
120
+ export type WipeMode = "reveal" | "cover";
121
+ /**
122
+ * Full-screen transition type used by {@link Game.transitionTo}.
123
+ */
124
+ export type ScreenTransitionType = "fade" | "wipe" | "slide" | "iris" | "pixelate" | "flash";
125
+ /**
126
+ * Optional tuning values for {@link Game.animateWipe}.
46
127
  *
47
- * const player = new Player(400, 300);
48
- * game.add(player);
49
- * ```
128
+ * All fields are optional. Omitted fields use the engine defaults.
129
+ */
130
+ export interface WipeOptions {
131
+ /** Whether the wipe reveals the sprite or covers it away. */
132
+ mode?: WipeMode;
133
+ /** Primary wipe direction. */
134
+ direction?: FlowDirection;
135
+ /** Total effect duration in **milliseconds**. */
136
+ durationMs?: number;
137
+ /** Whether the original sprite is destroyed for `mode: "cover"`. */
138
+ destroySprite?: boolean;
139
+ }
140
+ /**
141
+ * Optional tuning values for {@link Game.transitionTo}.
142
+ *
143
+ * MinimoJS scene transitions operate on frozen snapshots of the outgoing and
144
+ * incoming scenes. The target scene is created immediately, then both
145
+ * snapshots are composited for the duration of the effect.
146
+ */
147
+ export interface SceneTransitionOptions {
148
+ /** Required transition style. */
149
+ type: ScreenTransitionType;
150
+ /** Total transition duration in **milliseconds**. */
151
+ durationMs?: number;
152
+ /** Optional color used by `fade` and `flash`. */
153
+ color?: string;
154
+ /** Direction used by `wipe` and `slide`. */
155
+ direction?: FlowDirection;
156
+ /** Optional iris center X position in canvas pixels. */
157
+ centerX?: number;
158
+ /** Optional iris center Y position in canvas pixels. */
159
+ centerY?: number;
160
+ /** Maximum pixel block size used by `pixelate`. */
161
+ pixelSize?: number;
162
+ }
163
+ /**
164
+ * Optional tuning values for {@link Game.animateTrail}.
165
+ *
166
+ * All fields are optional. Omitted fields use the engine defaults.
167
+ */
168
+ export interface TrailOptions {
169
+ /** How long the emitter spawns afterimages, in **milliseconds**. */
170
+ durationMs?: number;
171
+ /** Time between emitted afterimages, in **milliseconds**. */
172
+ spacingMs?: number;
173
+ /** Lifetime of each afterimage before it disappears, in **milliseconds**. */
174
+ fadeMs?: number;
175
+ /** Starting opacity multiplier for each emitted afterimage, in range `[0, 1]`. */
176
+ alpha?: number;
177
+ /** Final scale multiplier reached by each afterimage before it vanishes. */
178
+ scaleTo?: number;
179
+ }
180
+ /**
181
+ * How a {@link BackgroundLayer} image is fit inside its destination rectangle.
182
+ *
183
+ * - `"none"`: draws the image at its original size with no scaling.
184
+ * - `"stretch"`: fills the destination exactly, ignoring aspect ratio.
185
+ * - `"contain"`: preserves aspect ratio and keeps the entire image visible.
186
+ * - `"cover"`: preserves aspect ratio and fully covers the destination, cropping if needed.
187
+ */
188
+ export type BackgroundFit = "none" | "stretch" | "contain" | "cover";
189
+ /**
190
+ * Minimal scene contract understood by {@link Game.start} and {@link Game.reset}.
191
+ *
192
+ * Scene methods are invoked directly on the scene instance, so class-based
193
+ * scenes keep their expected `this` value.
50
194
  */
51
- export declare class Sprite {
195
+ export interface IScene {
52
196
  /**
53
- * The emoji character used to render this sprite.
54
- * Must be a single emoji. Change this at runtime to animate between frames.
55
- * @example "🔥", "⭐", "🐢"
197
+ * Registers images this scene needs that the rest of the game does not.
198
+ *
199
+ * **Only for games with many scenes that each carry many assets of their
200
+ * own**, such as a game with many levels, where a player does not reach
201
+ * every scene in a session and loading all of them at boot would make the
202
+ * first wait needlessly long. Every other game should load its images in
203
+ * {@link Game.onPreload}, once, at boot.
204
+ *
205
+ * Called whenever the scene is entered — by {@link Game.start},
206
+ * {@link Game.reset}, or {@link Game.transitionTo} — before
207
+ * {@link IScene.onCreate}. Call {@link Game.loadAssets},
208
+ * {@link Game.loadImage}, or {@link Game.loadSound} inside it, as inside `game.onPreload`. Images that
209
+ * are already loaded are skipped, so replaying a scene loads nothing.
210
+ *
211
+ * When images are pending, the scene being left freezes, dimmed, under a
212
+ * progress ring until they load, and only then is this scene created.
213
+ * Because of that, `reset()` and `transitionTo()` may return before this
214
+ * scene exists: continue in `onCreate()`, not in the code after the call.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * class Level {
219
+ * constructor(n) { this.n = n; }
220
+ * onPreload() {
221
+ * game.loadImage(`level-${this.n}-bg`, `assets/level-${this.n}-bg.png`);
222
+ * }
223
+ * onCreate() {
224
+ * game.addBackground(new BackgroundLayer(`level-${this.n}-bg`));
225
+ * }
226
+ * }
227
+ * ```
56
228
  */
57
- sprite: string;
229
+ onPreload?(): void;
230
+ /**
231
+ * Called when the scene is created, before the first frame and again after
232
+ * each {@link Game.reset} that targets this scene. When the scene has an
233
+ * {@link IScene.onPreload} with images still loading, it is called once they
234
+ * have loaded.
235
+ */
236
+ onCreate?(): void;
237
+ /**
238
+ * Called once per frame after timers, animation, and physics updates.
239
+ *
240
+ * @param dt - Delta time in seconds since the previous frame.
241
+ */
242
+ onUpdate?(dt: number): void;
243
+ }
244
+ /**
245
+ * Base class for all renderable MinimoJS actors.
246
+ *
247
+ * Concrete subclasses provide their own visual content while inheriting the
248
+ * shared transform, visibility, physics, and animation state required by the
249
+ * engine.
250
+ */
251
+ export declare abstract class Sprite {
252
+ protected constructor(game?: Game | null);
253
+ /**
254
+ * Game instance associated with this sprite, if any.
255
+ */
256
+ get game(): Game | null;
58
257
  /**
59
258
  * X position in world space (horizontal center of the sprite), in pixels.
60
259
  * Positive X points right. Updated each frame by: `x += vx * dt`.
@@ -68,10 +267,80 @@ export declare class Sprite {
68
267
  */
69
268
  y: number;
70
269
  /**
71
- * Width and height of the sprite's bounding square, in pixels.
72
- * Used for both canvas rendering (font size) and AABB collision detection.
270
+ * Resolved center X used internally by rendering, hit testing, and collisions.
73
271
  */
74
- size: number;
272
+ get renderX(): number;
273
+ /**
274
+ * Resolved center Y used internally by rendering, hit testing, and collisions.
275
+ */
276
+ get renderY(): number;
277
+ /**
278
+ * Visual scale multiplier applied to this sprite's logical width/height.
279
+ * Default: `1`.
280
+ */
281
+ scale: number;
282
+ /**
283
+ * Base logical width in pixels before applying {@link Sprite.scale}.
284
+ */
285
+ abstract get width(): number;
286
+ /**
287
+ * Base logical height in pixels before applying {@link Sprite.scale}.
288
+ */
289
+ abstract get height(): number;
290
+ /**
291
+ * Effective rendered/collision width in pixels.
292
+ */
293
+ get displayWidth(): number;
294
+ /**
295
+ * Effective rendered/collision height in pixels.
296
+ */
297
+ get displayHeight(): number;
298
+ /**
299
+ * Optional logical body width used by physics helpers and collision checks.
300
+ *
301
+ * When `null` (default), MinimoJS uses the sprite's visual {@link Sprite.width}.
302
+ * When set, this value is scaled by {@link Sprite.scale} the same way as the
303
+ * visual sprite size.
304
+ */
305
+ bodyWidth: number | null;
306
+ /**
307
+ * Optional logical body height used by physics helpers and collision checks.
308
+ *
309
+ * When `null` (default), MinimoJS uses the sprite's visual {@link Sprite.height}.
310
+ * When set, this value is scaled by {@link Sprite.scale} the same way as the
311
+ * visual sprite size.
312
+ */
313
+ bodyHeight: number | null;
314
+ /**
315
+ * Horizontal body offset, in local sprite pixels before scale is applied.
316
+ *
317
+ * Positive values move the collision body to the right of the sprite's rendered center.
318
+ * Negative values move it to the left.
319
+ */
320
+ bodyOffsetX: number;
321
+ /**
322
+ * Vertical body offset, in local sprite pixels before scale is applied.
323
+ *
324
+ * Positive values move the collision body downward relative to the sprite's
325
+ * rendered center. Negative values move it upward.
326
+ */
327
+ bodyOffsetY: number;
328
+ /**
329
+ * Effective collision-body width in pixels after applying {@link Sprite.scale}.
330
+ */
331
+ get bodyDisplayWidth(): number;
332
+ /**
333
+ * Effective collision-body height in pixels after applying {@link Sprite.scale}.
334
+ */
335
+ get bodyDisplayHeight(): number;
336
+ /**
337
+ * Resolved body center X used internally by physics helpers and collision checks.
338
+ */
339
+ get bodyCenterX(): number;
340
+ /**
341
+ * Resolved body center Y used internally by physics helpers and collision checks.
342
+ */
343
+ get bodyCenterY(): number;
75
344
  /**
76
345
  * CSS text color used when rendering this sprite.
77
346
  *
@@ -80,6 +349,19 @@ export declare class Sprite {
80
349
  * depending on browser behavior.
81
350
  */
82
351
  color: string;
352
+ /**
353
+ * Physics body type flag.
354
+ *
355
+ * - `false` (default): the sprite is dynamic and can be moved by velocity,
356
+ * gravity, and explicit collision resolution.
357
+ * - `true`: the sprite is static and is not moved by the engine's built-in
358
+ * velocity/gravity integration. Static sprites act as stable obstacles for
359
+ * simple platform collisions.
360
+ *
361
+ * Static sprites can still be repositioned manually by setting `x` and `y`
362
+ * directly in your own game code.
363
+ */
364
+ isStatic: boolean;
83
365
  /**
84
366
  * Visual rotation of the sprite in degrees.
85
367
  * `0` = upright. Positive values rotate clockwise.
@@ -145,24 +427,415 @@ export declare class Sprite {
145
427
  */
146
428
  gravityScale: number;
147
429
  /**
148
- * Creates a new Sprite with the given emoji and optional position.
430
+ * Optional name, so code can ask an object what it is. Names may repeat,
431
+ * like a `name` attribute in the DOM. The engine never reads it.
432
+ * A sprite created from a design file takes the object's `name`.
433
+ *
434
+ * @example
435
+ * ```ts
436
+ * if (other.name === "door") openDoor();
437
+ * ```
438
+ */
439
+ name: string | undefined;
440
+ /**
441
+ * Tags for grouping, like CSS classes in the DOM. Empty by default. The
442
+ * engine never reads them. A sprite created from a design file takes the
443
+ * object's `tags`, which {@link Game.registerBuilderByTag} also matches.
444
+ *
445
+ * @example
446
+ * ```ts
447
+ * if (other.tags.includes("coin")) collect(other);
448
+ * ```
449
+ */
450
+ tags: string[];
451
+ /**
452
+ * The game's own values for this object, such as a button's action or an
453
+ * enemy's speed. An empty object by default, so `sprite.data.hp = 3` needs
454
+ * no check. The engine never reads it. A sprite created from a design file
455
+ * takes a copy of the object's `data`.
456
+ */
457
+ data: Record<string, unknown>;
458
+ /**
459
+ * Stable cache key describing the sprite's rendered appearance.
460
+ *
461
+ * The renderer uses this to reuse prerendered canvases across frames.
462
+ */
463
+ abstract getRenderCacheKey(): string;
464
+ protected getAnchorOffsetX(): number;
465
+ protected getAnchorOffsetY(): number;
466
+ }
467
+ /**
468
+ * A 2D game object rendered as an emoji on the canvas.
469
+ *
470
+ * Instantiate directly or extend to create custom sprite types.
471
+ * Register with the engine by passing the instance to {@link Game.add}.
472
+ *
473
+ * **Coordinate system:** center-based world space. `(x, y)` is the center of
474
+ * the sprite. Positive X = right, positive Y = down.
475
+ *
476
+ * **Lifecycle:** A sprite exists until {@link Game.destroySprite} is called or
477
+ * {@link Game.reset} is invoked. After destruction, do not read or write its fields.
478
+ *
479
+ * @example
480
+ * ```ts
481
+ * const coin = new EmojiSprite("🪙", 300, 200, 32);
482
+ * game.add(coin);
483
+ * ```
484
+ */
485
+ export declare class EmojiSprite extends Sprite {
486
+ /**
487
+ * The emoji character used to render this sprite.
488
+ * Must be a single emoji. Change this at runtime to animate between frames.
489
+ * @example "🔥", "⭐", "🐢"
490
+ */
491
+ sprite: string;
492
+ get size(): number;
493
+ get width(): number;
494
+ get height(): number;
495
+ get displaySize(): number;
496
+ /**
497
+ * Creates a new EmojiSprite with the given emoji, optional position, and base size.
149
498
  * All other properties use their defaults and can be set after construction.
150
499
  *
151
500
  * @param sprite - The emoji character to render. Must be a single emoji.
152
- * Image sprites are NOT supported — emoji only.
501
+ * Use {@link ImageSprite} for preloaded bitmap textures.
153
502
  * @example "🔥", "⭐", "🐢", "💣", "👾"
154
503
  * @param x - Initial X position in world space (center), in pixels. Default: `0`.
155
504
  * @param y - Initial Y position in world space (center), in pixels. Default: `0`.
505
+ * @param size - Base sprite size in pixels. Default: `32`.
156
506
  *
157
507
  * @example
158
508
  * ```ts
159
- * const enemy = new Sprite("👾", 200, 100);
160
- * enemy.size = 40;
509
+ * const enemy = new EmojiSprite("👾", 200, 100, 40);
161
510
  * game.add(enemy);
162
511
  * ```
163
512
  */
164
- constructor(sprite: string, x?: number, y?: number);
513
+ constructor(sprite: string, x?: number, y?: number, size?: number);
514
+ getRenderCacheKey(): string;
515
+ }
516
+ /**
517
+ * A renderable sprite backed by a preloaded image asset.
518
+ *
519
+ * Width and height are always resolved from the current texture. To resize the
520
+ * sprite visually, use {@link Sprite.scale}.
521
+ */
522
+ export declare class ImageSprite extends Sprite {
523
+ get imageKey(): string;
524
+ get width(): number;
525
+ get height(): number;
526
+ /**
527
+ * Creates a new image-backed sprite.
528
+ *
529
+ * @param game - Game instance used to resolve the texture key.
530
+ * @param imageKey - Texture key previously registered with {@link Game.loadImage} or {@link Game.createTexture}.
531
+ * @param x - Initial X position in world space (center), in pixels. Default: `0`.
532
+ * @param y - Initial Y position in world space (center), in pixels. Default: `0`.
533
+ */
534
+ constructor(game: Game, imageKey: string, x?: number, y?: number);
535
+ /**
536
+ * Replaces the current texture with another preloaded image.
537
+ *
538
+ * @param imageKey - New texture key to render.
539
+ */
540
+ setTexture(imageKey: string): void;
541
+ getRenderCacheKey(): string;
542
+ }
543
+ /**
544
+ * A renderable sprite backed by a per-instance canvas that is repainted on demand.
545
+ *
546
+ * `DrawSprite` is useful for procedural shapes, gauges, charts, minimaps, and
547
+ * HUD widgets whose appearance changes often and is easier to express with
548
+ * Canvas 2D drawing commands than with emoji, text, or image swaps.
549
+ *
550
+ * Treat `DrawSprite` as a specialized tool, not the default sprite type.
551
+ * Because it may execute custom Canvas 2D drawing code repeatedly, overusing it
552
+ * can affect game performance much more than regular {@link EmojiSprite},
553
+ * {@link ImageSprite}, or {@link TextSprite} instances.
554
+ *
555
+ * Prefer the other sprite types whenever they can express the same result more
556
+ * simply. Reach for `DrawSprite` only when you truly need procedural drawing or
557
+ * custom per-sprite canvas rendering that the built-in sprite types cannot
558
+ * provide cleanly.
559
+ *
560
+ * MinimoJS creates and owns an internal canvas for each `DrawSprite` instance.
561
+ * Before every engine render that needs this sprite's surface, the engine:
562
+ *
563
+ * 1. Resolves the sprite's internal canvas size
564
+ * 2. Optionally clears and repaints that internal canvas
565
+ * 3. Draws the resulting canvas like any other sprite surface
566
+ *
567
+ * By default, `DrawSprite` is live-rendered: the engine clears the internal
568
+ * canvas and calls {@link DrawSprite.redraw} every frame.
569
+ *
570
+ * Set {@link DrawSprite.frozen} to `true` if you want to keep and reuse the
571
+ * last rendered canvas contents without repainting on each frame. This is
572
+ * useful for shapes or procedural art that you only want to draw once.
573
+ *
574
+ * While `frozen` is `true`, MinimoJS reuses the existing surface exactly as-is:
575
+ * it does not clear the canvas and does not call {@link DrawSprite.redraw}
576
+ * again, unless the surface does not exist yet or its size had to be rebuilt.
577
+ *
578
+ * This means freezing is a rendering optimization and content-preservation
579
+ * flag, not a separate caching system. You can switch `frozen` on or off at
580
+ * runtime whenever it makes sense for your sprite.
581
+ *
582
+ * The local drawing coordinate system uses the sprite surface itself:
583
+ * - `(0, 0)` is the top-left corner of the internal canvas
584
+ * - `width` / `height` match the sprite's logical size before `scale`
585
+ * - draw centered content yourself if you want the visual origin in the middle
586
+ *
587
+ * Override {@link DrawSprite.redraw} in a subclass, or assign your own method
588
+ * on an instance if you prefer an inline style in JavaScript.
589
+ */
590
+ export declare class DrawSprite extends Sprite {
591
+ /**
592
+ * When `false` (default), MinimoJS clears this sprite's internal canvas and
593
+ * calls {@link DrawSprite.redraw} on every render pass.
594
+ *
595
+ * When `true`, MinimoJS keeps and reuses the existing canvas contents without
596
+ * clearing or repainting them again, unless the internal surface does not yet
597
+ * exist or had to be resized.
598
+ *
599
+ * Use this when your procedural drawing becomes static after its first paint,
600
+ * or when you want explicit manual control over when the sprite is redrawn by
601
+ * toggling `frozen` at runtime.
602
+ */
603
+ frozen: boolean;
604
+ get width(): number;
605
+ get height(): number;
606
+ /**
607
+ * Creates a new dynamic canvas-backed sprite.
608
+ *
609
+ * @param width - Internal canvas width in pixels. Minimum `1`.
610
+ * @param height - Internal canvas height in pixels. Minimum `1`.
611
+ * @param x - Initial X position in world space (center), in pixels. Default: `0`.
612
+ * @param y - Initial Y position in world space (center), in pixels. Default: `0`.
613
+ */
614
+ constructor(width: number, height: number, x?: number, y?: number);
615
+ /**
616
+ * Called by the engine whenever the sprite's internal surface must be repainted.
617
+ *
618
+ * The provided context is already cleared and reset to the default 2D canvas
619
+ * state for the current surface size. MinimoJS repaints each `DrawSprite` at
620
+ * most once per render pass while it is not {@link DrawSprite.frozen}, so
621
+ * repeated snapshot reads during the same frame reuse the already-redrawn
622
+ * surface.
623
+ *
624
+ * @param ctx - The sprite's internal 2D drawing context.
625
+ */
626
+ redraw(_ctx: CanvasRenderingContext2D): void;
627
+ getRenderCacheKey(): string;
165
628
  }
629
+ /**
630
+ * A renderable text actor that participates in the same animation/effects
631
+ * pipeline as regular sprites.
632
+ *
633
+ * Use `TextSprite` when the content is primarily text, or when you need text
634
+ * layout features such as wrapping, fixed button sizes, background/border, or
635
+ * text stroke.
636
+ *
637
+ * For controls that are only a single emoji, prefer {@link EmojiSprite}. Emoji-only
638
+ * buttons usually behave better as sprites because they do not need text
639
+ * padding/layout and their bounds match the rendered emoji more directly.
640
+ */
641
+ export declare class TextSprite extends Sprite {
642
+ anchorX: "left" | "center" | "right";
643
+ anchorY: "top" | "middle" | "bottom";
644
+ text: string;
645
+ /**
646
+ * CSS font family. Default: `monospace`, which needs no download. Name a web
647
+ * font here, and register it with {@link Game.requireFont}, to use one.
648
+ */
649
+ fontFamily: string;
650
+ fontSize: number;
651
+ fontWeight: string;
652
+ lineHeight: number;
653
+ maxWidth: number;
654
+ fixedWidth: number;
655
+ fixedHeight: number;
656
+ paddingX: number;
657
+ paddingY: number;
658
+ backgroundColor: string | null;
659
+ borderColor: string | null;
660
+ borderWidth: number;
661
+ cornerRadius: number;
662
+ strokeColor: string | null;
663
+ strokeWidth: number;
664
+ textAlign: CanvasTextAlign;
665
+ get width(): number;
666
+ get height(): number;
667
+ constructor(text: string, x?: number, y?: number, fontSizeOrConfig?: number | TextSpriteConfig, config?: TextSpriteConfig);
668
+ getRenderCacheKey(): string;
669
+ get align(): CanvasTextAlign;
670
+ set align(value: CanvasTextAlign);
671
+ protected getAnchorOffsetX(): number;
672
+ protected getAnchorOffsetY(): number;
673
+ }
674
+ export type TextSpriteConfig = {
675
+ anchorX?: "left" | "center" | "right";
676
+ anchorY?: "top" | "middle" | "bottom";
677
+ fontFamily?: string;
678
+ fontSize?: number;
679
+ fontWeight?: string;
680
+ lineHeight?: number;
681
+ maxWidth?: number;
682
+ fixedWidth?: number;
683
+ fixedHeight?: number;
684
+ paddingX?: number;
685
+ paddingY?: number;
686
+ backgroundColor?: string | null;
687
+ borderColor?: string | null;
688
+ borderWidth?: number;
689
+ cornerRadius?: number;
690
+ strokeColor?: string | null;
691
+ strokeWidth?: number;
692
+ textAlign?: CanvasTextAlign;
693
+ align?: CanvasTextAlign;
694
+ };
695
+ export type FontRequirementOptions = {
696
+ weight?: string;
697
+ style?: "normal" | "italic" | "oblique";
698
+ size?: number;
699
+ sampleText?: string;
700
+ };
701
+ /**
702
+ * A static image-based background layer rendered behind all sprites.
703
+ *
704
+ * Background layers are visual-only: they do not participate in physics,
705
+ * collisions, input hit-testing, or sprite queries.
706
+ *
707
+ * `x` / `y` use **top-left screen-space coordinates**, unlike {@link Sprite},
708
+ * which uses center-based world space.
709
+ *
710
+ * The texture referenced by {@link BackgroundLayer.imageKey} must be registered
711
+ * with {@link Game.loadImage} during {@link Game.onPreload}, or created
712
+ * dynamically with {@link Game.createTexture}.
713
+ *
714
+ * @example
715
+ * ```ts
716
+ * game.onPreload = () => {
717
+ * game.loadImage("sky", "assets/sky.png");
718
+ * };
719
+ *
720
+ * game.onCreate = () => {
721
+ * const bg = game.addBackground(new BackgroundLayer("sky"));
722
+ * bg.fit = "cover";
723
+ * };
724
+ * ```
725
+ */
726
+ export declare class BackgroundLayer {
727
+ /**
728
+ * Key of the preloaded image to render.
729
+ */
730
+ imageKey: string;
731
+ /**
732
+ * Left edge of the destination rectangle in screen space, in pixels.
733
+ */
734
+ x: number;
735
+ /**
736
+ * Top edge of the destination rectangle in screen space, in pixels.
737
+ */
738
+ y: number;
739
+ /**
740
+ * Width of the destination rectangle in pixels.
741
+ * If `0` (default), the canvas width is used.
742
+ */
743
+ width: number;
744
+ /**
745
+ * Height of the destination rectangle in pixels.
746
+ * If `0` (default), the canvas height is used.
747
+ */
748
+ height: number;
749
+ /**
750
+ * Opacity of the layer in range `[0, 1]`.
751
+ */
752
+ alpha: number;
753
+ /**
754
+ * Controls whether the layer is drawn.
755
+ */
756
+ visible: boolean;
757
+ /**
758
+ * Orders background layers relative to each other.
759
+ * Higher values render on top of lower background layers, but still behind sprites.
760
+ */
761
+ layer: number;
762
+ /**
763
+ * How the image is fit inside the destination rectangle.
764
+ * Default: `"cover"`.
765
+ */
766
+ fit: BackgroundFit;
767
+ /**
768
+ * Optional name, so code can ask a layer what it is. Names may repeat. The
769
+ * engine never reads it. See {@link Sprite.name}.
770
+ */
771
+ name: string | undefined;
772
+ /**
773
+ * Tags for grouping. Empty by default. The engine never reads them. See
774
+ * {@link Sprite.tags}.
775
+ */
776
+ tags: string[];
777
+ /**
778
+ * The game's own values for this layer. An empty object by default. The
779
+ * engine never reads it. See {@link Sprite.data}.
780
+ */
781
+ data: Record<string, unknown>;
782
+ /**
783
+ * Creates a new background layer.
784
+ *
785
+ * @param imageKey - Preloaded image key previously registered with {@link Game.loadImage}.
786
+ * @param x - Destination rectangle left edge in screen space. Default: `0`.
787
+ * @param y - Destination rectangle top edge in screen space. Default: `0`.
788
+ * @param width - Destination rectangle width. `0` means canvas width. Default: `0`.
789
+ * @param height - Destination rectangle height. `0` means canvas height. Default: `0`.
790
+ */
791
+ constructor(imageKey: string, x?: number, y?: number, width?: number, height?: number);
792
+ }
793
+ /**
794
+ * The objects {@link Game.createObjectList} created, in the order of their
795
+ * data, and searches on them.
796
+ *
797
+ * An `ObjectList` only holds and finds its objects; it never changes them.
798
+ * Remove them through the game, as any other object:
799
+ *
800
+ * ```ts
801
+ * for (const obj of ui.objects) {
802
+ * if (obj instanceof BackgroundLayer) game.destroyBackgroundLayer(obj);
803
+ * else game.destroySprite(obj);
804
+ * }
805
+ * ```
806
+ *
807
+ * Searches read each object's current {@link Sprite.name} and
808
+ * {@link Sprite.tags}. In TypeScript, name the type you expect:
809
+ * `ui.findByName<ImageSprite>("play")`.
810
+ */
811
+ export declare class ObjectList {
812
+ /** Every object created, in the order of the data. */
813
+ readonly objects: readonly (Sprite | BackgroundLayer)[];
814
+ /**
815
+ * Returns the first object whose `name` is `name`, in order.
816
+ * Throws an error naming `name` when there is none.
817
+ *
818
+ * @example
819
+ * ```ts
820
+ * const play = ui.findByName("play");
821
+ * ```
822
+ */
823
+ findByName<T extends Sprite | BackgroundLayer = Sprite | BackgroundLayer>(name: string): T;
824
+ /** Returns every object whose `name` is `name`, in order; an empty list when there is none. */
825
+ findAllByName<T extends Sprite | BackgroundLayer = Sprite | BackgroundLayer>(name: string): T[];
826
+ /**
827
+ * Returns the first object whose `tags` include `tag`, in order.
828
+ * Throws an error naming `tag` when there is none.
829
+ */
830
+ findByTag<T extends Sprite | BackgroundLayer = Sprite | BackgroundLayer>(tag: string): T;
831
+ /** Returns every object whose `tags` include `tag`, in order; an empty list when there is none. */
832
+ findAllByTag<T extends Sprite | BackgroundLayer = Sprite | BackgroundLayer>(tag: string): T[];
833
+ }
834
+ /**
835
+ * Builds the object for a design object whose tags include the tag it was
836
+ * registered for. See {@link Game.registerBuilderByTag}.
837
+ */
838
+ export type ObjectBuilder = (obj: DesignObject, game: Game) => Sprite | BackgroundLayer;
166
839
  /**
167
840
  * Snapshot of an active pointer tracked by the engine.
168
841
  *
@@ -189,6 +862,36 @@ export interface PointerInfo {
189
862
  */
190
863
  pressed: boolean;
191
864
  }
865
+ /**
866
+ * Information about a resolved AABB collision.
867
+ *
868
+ * Flags are reported relative to the **first** sprite passed to
869
+ * {@link Game.collide}. For example, `bottom = true` means the bottom side of
870
+ * the first sprite contacted the top side of the second sprite.
871
+ */
872
+ export interface CollisionInfo {
873
+ /**
874
+ * `true` when the first sprite's left side hit the second sprite.
875
+ */
876
+ left: boolean;
877
+ /**
878
+ * `true` when the first sprite's right side hit the second sprite.
879
+ */
880
+ right: boolean;
881
+ /**
882
+ * `true` when the first sprite's top side hit the second sprite from below.
883
+ */
884
+ top: boolean;
885
+ /**
886
+ * `true` when the first sprite's bottom side landed on the second sprite.
887
+ */
888
+ bottom: boolean;
889
+ /**
890
+ * Convenience flag for platformers.
891
+ * Equivalent to `bottom = true`.
892
+ */
893
+ grounded: boolean;
894
+ }
192
895
  /**
193
896
  * # MinimoJS v1 — AI Agent Integration Guide
194
897
  *
@@ -198,18 +901,88 @@ export interface PointerInfo {
198
901
  *
199
902
  * ---
200
903
  *
904
+ * ## ES Module Only
905
+ *
906
+ * MinimoJS is an **ES module only** package.
907
+ * You must import it with standard ESM syntax such as:
908
+ *
909
+ * ```ts
910
+ * import { Game, EmojiSprite } from "minimojs";
911
+ * ```
912
+ *
913
+ * In the browser, use it from a module script:
914
+ *
915
+ * ```html
916
+ * <script type="module">
917
+ * import { Game, EmojiSprite } from "./dist/minimo.js";
918
+ * </script>
919
+ * ```
920
+ *
921
+ * Or from a CDN:
922
+ *
923
+ * ```ts
924
+ * import { Game, EmojiSprite } from "https://cdn.jsdelivr.net/npm/minimojs@<version>/dist/minimo.js";
925
+ * ```
926
+ *
927
+ * Do NOT use a classic `<script>` tag without `type="module"`.
928
+ * Do NOT expect a global `window.MinimoJS`.
929
+ * Do NOT use `require("minimojs")` (CommonJS is not supported).
930
+ *
931
+ * ---
932
+ *
933
+ * ## Font Setup
934
+ *
935
+ * `drawText()` and `TextSprite` default to `monospace`, which every device
936
+ * has, so a game that names no font downloads none and waits for none. To use
937
+ * a web font, declare it in your page, register it with {@link Game.requireFont}
938
+ * before calling {@link Game.start}, and name it in {@link TextSprite.fontFamily}.
939
+ *
940
+ * Prefer {@link TextSprite} for persistent UI text, interactive labels,
941
+ * buttons, fixed-size text boxes, and styled text elements. Keep
942
+ * `drawText()` for simple screen-space overlays such as HUD counters, debug
943
+ * text, or other text that is redrawn every frame.
944
+ *
945
+ * You MUST still declare the fonts yourself in your `index.html`. MinimoJS
946
+ * does NOT download, inject, or manage web fonts for you. If a font is missing,
947
+ * the browser falls back to `monospace`.
948
+ *
949
+ * Example `index.html` `<head>` setup:
950
+ *
951
+ * ```html
952
+ * <link rel="preconnect" href="https://fonts.googleapis.com" />
953
+ * <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
954
+ * <link
955
+ * href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap"
956
+ * rel="stylesheet"
957
+ * />
958
+ * ```
959
+ *
960
+ * Example custom font registration:
961
+ *
962
+ * ```ts
963
+ * const game = new Game(720, 1280);
964
+ * game.requireFont('"Bangers"', { weight: "400" });
965
+ * game.start();
966
+ * ```
967
+ *
968
+ * ---
969
+ *
201
970
  * ## Quick Start
202
971
  *
203
972
  * ```ts
204
- * import { Game, Sprite } from "https://cdn.jsdelivr.net/npm/minimojs@<version>/dist/minimo.js";
973
+ * import { Game, ImageSprite } from "https://cdn.jsdelivr.net/npm/minimojs@<version>/dist/minimo.js";
974
+ *
975
+ * const game = new Game(720, 1280);
976
+ *
977
+ * game.onPreload = () => {
978
+ * game.loadImage("player", "assets/player.png");
979
+ * };
205
980
  *
206
- * const game = new Game(800, 600);
981
+ * let player: ImageSprite;
207
982
  *
208
- * const player = new Sprite("🐢");
209
- * player.x = 400;
210
- * player.y = 500;
211
- * player.size = 48;
212
- * game.add(player);
983
+ * game.onCreate = () => {
984
+ * player = game.add(new ImageSprite(game, "player", 400, 500));
985
+ * };
213
986
  *
214
987
  * game.onUpdate = (dt) => {
215
988
  * if (game.isKeyDown("ArrowLeft")) player.vx = -200;
@@ -222,6 +995,13 @@ export interface PointerInfo {
222
995
  * game.start();
223
996
  * ```
224
997
  *
998
+ * Prototyping, and have no art yet? Swap the texture for an emoji and drop the
999
+ * preload entirely — everything else stays the same:
1000
+ *
1001
+ * ```ts
1002
+ * const player = game.add(new EmojiSprite("🐢", 400, 500, 48));
1003
+ * ```
1004
+ *
225
1005
  * ---
226
1006
  *
227
1007
  * ## Engine Philosophy
@@ -235,7 +1015,8 @@ export interface PointerInfo {
235
1015
  * ## Flat API
236
1016
  *
237
1017
  * ALL engine functionality is on the `game` object.
238
- * Do not look for sub-objects like `game.physics`, `game.input`, etc. They do not exist.
1018
+ * Do not look for nested subsystem objects like `game.input.keyboard`,
1019
+ * `game.physics.world`, etc. They do not exist in MinimoJS v1.
239
1020
  *
240
1021
  * ---
241
1022
  *
@@ -246,13 +1027,28 @@ export interface PointerInfo {
246
1027
  *
247
1028
  * ---
248
1029
  *
249
- * ## Emoji-Only Sprites
250
- *
251
- * Every sprite MUST use a single emoji character as its visual representation.
252
- * PNG, SVG, spritesheet, and image sprites are NOT supported.
253
- * Use Unicode emoji: `"🔥"`, `"⭐"`, `"💣"`, `"🐢"`, `"👾"`, `"🧱"`, etc.
254
- * AI agents can also use text-like emojis (regional indicators, symbols, letters)
255
- * to build fun title art, HUD labels, and expressive in-game text.
1030
+ * ## Choosing a Visual Source
1031
+ *
1032
+ * A sprite's look comes from one of four concrete types, all of which extend the
1033
+ * shared abstract {@link Sprite} type. Use `Sprite` as the type in your own
1034
+ * signatures; never construct it directly.
1035
+ *
1036
+ * 1. {@link ImageSprite} — the game's own images, and the first option to reach
1037
+ * for. Register a texture with {@link Game.loadImage} inside
1038
+ * {@link Game.onPreload}, or build one at runtime with
1039
+ * {@link Game.createTexture}, then render it with
1040
+ * `new ImageSprite(game, key, x, y)`. An image looks identical on every
1041
+ * device and belongs to the game.
1042
+ * 2. {@link EmojiSprite} — a single Unicode emoji, and the shortest path to a
1043
+ * first prototype: `new EmojiSprite("🐢", x, y, size)`. Note that an
1044
+ * emoji is drawn with the player's own system emoji font, so the same game
1045
+ * looks different across iOS, Android, and Windows, and a glyph the platform
1046
+ * lacks renders as an empty box. Prefer an image whenever the look matters.
1047
+ * 3. {@link TextSprite} — text, labels, and buttons.
1048
+ * 4. {@link DrawSprite} — procedural Canvas 2D drawing, for shapes and gauges
1049
+ * the other three cannot express cleanly.
1050
+ *
1051
+ * Emoji and images mix freely in one game.
256
1052
  *
257
1053
  * ---
258
1054
  *
@@ -268,7 +1064,7 @@ export interface PointerInfo {
268
1064
  *
269
1065
  * ALL time parameters to engine methods are in **milliseconds (ms)**.
270
1066
  * This includes: {@link Game.addTimer}, {@link Game.animateAlpha},
271
- * {@link Game.animateRotation}, and {@link Game.sound}.
1067
+ * {@link Game.animateRotation}, {@link Game.animateDeform}, and {@link Game.sound}.
272
1068
  *
273
1069
  * The `dt` parameter in {@link Game.onUpdate} is an exception — it is in
274
1070
  * **seconds** for convenient velocity math (`position += velocity * dt`).
@@ -320,10 +1116,10 @@ export interface PointerInfo {
320
1116
  *
321
1117
  * ---
322
1118
  *
323
- * ## Scene Initialization with `onCreate`
1119
+ * ## Scene Initialization with `IScene`
324
1120
  *
325
- * MinimoJS has NO scene system. Use {@link Game.onCreate} to build a scene.
326
- * The engine calls `onCreate`:
1121
+ * MinimoJS supports simple scene objects via {@link IScene}. The engine calls
1122
+ * a scene's `onCreate()`:
327
1123
  * - Once before the first frame (when {@link Game.start} is called).
328
1124
  * - Again after each {@link Game.reset}.
329
1125
  *
@@ -335,29 +1131,42 @@ export interface PointerInfo {
335
1131
  * - Scroll position (scrollX and scrollY reset to 0)
336
1132
  * - Per-frame input state (pressed keys/pointer)
337
1133
  *
338
- * After clearing, `reset()` calls `onCreate()` so your callback can rebuild the
339
- * new scene immediately. Simply re-add sprites and re-register timers.
1134
+ * After clearing, `reset()` calls the active scene's `onCreate()` so it can
1135
+ * rebuild immediately. Simply re-add sprites and re-register timers.
340
1136
  *
341
1137
  * ```ts
342
- * game.onCreate = () => {
343
- * // scene init: add sprites, setup timers
344
- * const skull = new Sprite("💀");
345
- * skull.x = 400; skull.y = 300; skull.size = 96;
346
- * game.add(skull);
347
- * };
1138
+ * class SkullScene implements IScene {
1139
+ * onCreate() {
1140
+ * const skull = new EmojiSprite("💀", 400, 300, 96);
1141
+ * game.add(skull);
1142
+ * }
348
1143
  *
349
- * game.onUpdate = (dt) => {
350
- * // normal per-frame update
351
- * };
1144
+ * onUpdate(dt: number) {
1145
+ * // normal per-frame update
1146
+ * }
1147
+ * }
352
1148
  *
353
- * game.start(); // calls onCreate() once before first frame
1149
+ * const scene = new SkullScene();
1150
+ * game.start(scene); // calls onCreate() once before first frame
354
1151
  * // later:
355
1152
  * game.reset(); // clears + calls onCreate() again
356
1153
  * ```
357
1154
  *
1155
+ * Legacy `game.onCreate` / `game.onUpdate` callbacks still work when no active
1156
+ * {@link IScene} is set.
1157
+ *
1158
+ * ### Loading a Scene's Own Images
1159
+ *
1160
+ * Load images in {@link Game.onPreload}: once, at boot. Only a game with many
1161
+ * scenes that each carry many assets of their own — typically a game with many
1162
+ * levels, whose player does not reach every level in a session — should give
1163
+ * scenes an {@link IScene.onPreload}. Entering such a scene loads its images
1164
+ * first, with the scene being left frozen and dimmed under a progress ring, so `reset()`
1165
+ * and `transitionTo()` may return before the new scene's `onCreate()` runs.
1166
+ *
358
1167
  * ---
359
1168
  *
360
- * ## Sprite Lifecycle Ownership
1169
+ * ## EmojiSprite Lifecycle Ownership
361
1170
  *
362
1171
  * The `Game` instance owns all sprites.
363
1172
  * - Create sprites with {@link Game.add}.
@@ -371,7 +1180,7 @@ export interface PointerInfo {
371
1180
  * ## Forbidden Features
372
1181
  *
373
1182
  * The following do NOT exist in MinimoJS v1. Do NOT attempt to use them:
374
- * - Scene system or scene manager
1183
+ * - Full scene manager architecture (scene stacks, transitions, loaders, etc.)
375
1184
  * - Entity Component System (ECS)
376
1185
  * - Physics engine (no Box2D, Matter.js, etc.)
377
1186
  * - Camera zoom or scale
@@ -379,8 +1188,7 @@ export interface PointerInfo {
379
1188
  * - Text input / HTML form elements
380
1189
  * - Parallax layers
381
1190
  * - Multiple cameras
382
- * - Collision resolution (only detection is supported)
383
- * - Image sprites (PNG, SVG, canvas, etc.)
1191
+ * - Full physics engine (only basic explicit AABB collision helpers are provided)
384
1192
  * - `setTimeout` or `setInterval`
385
1193
  */
386
1194
  export declare class Game {
@@ -395,7 +1203,8 @@ export declare class Game {
395
1203
  * game.gravityX = 0; // no horizontal gravity
396
1204
  * ```
397
1205
  */
398
- gravityX: number;
1206
+ get gravityX(): number;
1207
+ set gravityX(value: number);
399
1208
  /**
400
1209
  * Vertical gravity acceleration in pixels per second².
401
1210
  * Applied to every sprite whose {@link Sprite.gravityScale} is non-zero.
@@ -408,7 +1217,23 @@ export declare class Game {
408
1217
  * game.gravityY = 980; // standard downward gravity
409
1218
  * ```
410
1219
  */
411
- gravityY: number;
1220
+ get gravityY(): number;
1221
+ set gravityY(value: number);
1222
+ /**
1223
+ * Enables the basic collision-resolution helpers (`collide` / `collideAny`).
1224
+ *
1225
+ * When `false` (default), overlap detection still works, but collision
1226
+ * resolution helpers are unavailable.
1227
+ *
1228
+ * Set this to `true` for simple platformer-style collision handling.
1229
+ *
1230
+ * @example
1231
+ * ```ts
1232
+ * game.physics = true;
1233
+ * ```
1234
+ */
1235
+ get physics(): boolean;
1236
+ set physics(value: boolean);
412
1237
  /**
413
1238
  * Horizontal scroll offset of the world camera, in pixels.
414
1239
  * The canvas viewport is shifted left by `scrollX` — sprites with higher `x`
@@ -456,6 +1281,20 @@ export declare class Game {
456
1281
  from: string;
457
1282
  to: string;
458
1283
  } | null;
1284
+ /**
1285
+ * When `true`, MinimoJS draws every sprite's collision body as an overlay.
1286
+ *
1287
+ * This is a runtime debugging aid only. It does not change collisions,
1288
+ * input, rendering order, or physics behavior.
1289
+ */
1290
+ debugBodies: boolean;
1291
+ /**
1292
+ * When `true`, MinimoJS draws every sprite's input area as an overlay.
1293
+ *
1294
+ * This is a runtime debugging aid only. It does not change input behavior,
1295
+ * physics, or rendering.
1296
+ */
1297
+ debugInputAreas: boolean;
459
1298
  /**
460
1299
  * Background color for the full web page (`document.body`).
461
1300
  * Set to any valid CSS color string. Default: `null` (engine leaves page background unchanged).
@@ -469,24 +1308,49 @@ export declare class Game {
469
1308
  */
470
1309
  pageBackground: string | null;
471
1310
  /**
472
- * Scene creation callback.
1311
+ * Asset registration callback invoked once before the first scene is created.
1312
+ *
1313
+ * This is the normal place to load a game's images and sounds. Use it to register them
1314
+ * with {@link Game.loadAssets}, {@link Game.loadImage}, or {@link Game.loadSound}. The callback is synchronous: it should only
1315
+ * queue assets, not await network work.
1316
+ *
1317
+ * After `onPreload` returns, MinimoJS loads the queued images and sounds, together with
1318
+ * those of the first scene's {@link IScene.onPreload} if it has one, and
1319
+ * shows a loading line until they are ready. If any file fails, it asks the
1320
+ * player with `window.confirm` whether to retry them; declining leaves the
1321
+ * game on the loading screen and reports the failed files on the console.
1322
+ *
1323
+ * @example
1324
+ * ```ts
1325
+ * game.onPreload = () => {
1326
+ * game.loadImage("sky", "assets/sky.png");
1327
+ * game.loadImage("land", "assets/land.png");
1328
+ * };
1329
+ * ```
1330
+ */
1331
+ onPreload: (() => void) | null;
1332
+ /**
1333
+ * Legacy scene creation callback.
473
1334
  *
474
1335
  * Called once before the first frame on {@link Game.start}, and again after
475
- * each {@link Game.reset}. Use this to create sprites and timers for a scene.
1336
+ * each {@link Game.reset} when no active {@link IScene} is set.
476
1337
  *
477
1338
  * @example
478
1339
  * ```ts
479
1340
  * game.onCreate = () => {
480
- * const player = new Sprite("🐢");
1341
+ * const player = new EmojiSprite("🐢");
481
1342
  * player.x = 200;
482
1343
  * player.y = 300;
483
1344
  * game.add(player);
484
1345
  * };
485
1346
  * ```
486
1347
  */
487
- onCreate: (() => void) | null;
1348
+ get onCreate(): (() => void) | null;
1349
+ set onCreate(callback: (() => void) | null);
488
1350
  /**
489
- * Callback invoked once per frame after physics and timer updates.
1351
+ * Legacy per-frame callback invoked after physics and timer updates.
1352
+ *
1353
+ * This is used only when no active {@link IScene} is set.
490
1354
  *
491
1355
  * @param dt - Delta time in **seconds** since the last frame.
492
1356
  * Use this for velocity-based movement: `sprite.x += speed * dt`.
@@ -501,21 +1365,38 @@ export declare class Game {
501
1365
  * ```
502
1366
  */
503
1367
  onUpdate: ((dt: number) => void) | null;
1368
+ /**
1369
+ * Currently active scene object, if any.
1370
+ */
1371
+ get currentScene(): IScene | null;
1372
+ /**
1373
+ * Returns `true` while a full-screen scene transition is playing.
1374
+ */
1375
+ get isTransitioning(): boolean;
1376
+ /**
1377
+ * Returns `true` while images are loading: at boot, or while a scene with
1378
+ * pending images in its {@link IScene.onPreload} is being entered. While a
1379
+ * scene loads, the scene being left is frozen and `reset()` and
1380
+ * `transitionTo()` are ignored.
1381
+ */
1382
+ get isLoading(): boolean;
504
1383
  /**
505
1384
  * Creates a new MinimoJS game instance.
506
1385
  *
507
1386
  * The engine creates its own `<canvas>`, sets its dimensions, and appends it
508
1387
  * to `document.body`. The canvas is automatically centered and responsively
509
1388
  * scaled to use the maximum available viewport space while preserving aspect ratio.
1389
+ * For new mobile-first Minimo Games, prefer a portrait canvas such as `720x1280`.
510
1390
  *
511
- * @param width - Canvas width in pixels. Default: `800`.
512
- * @param height - Canvas height in pixels. Default: `600`.
1391
+ * @param width - Canvas width in pixels. Default: `720`.
1392
+ * @param height - Canvas height in pixels. Default: `1280`.
513
1393
  *
514
1394
  * @throws Error if a 2D context cannot be obtained.
515
1395
  *
516
1396
  * @example
517
1397
  * ```ts
518
- * const game = new Game(800, 600);
1398
+ * const game = new Game(720, 1280);
1399
+ * game.physics = true;
519
1400
  * ```
520
1401
  */
521
1402
  constructor(width?: number, height?: number);
@@ -526,98 +1407,350 @@ export declare class Game {
526
1407
  /**
527
1408
  * The height of the canvas in pixels. Read-only — set via constructor.
528
1409
  */
529
- get height(): number;
1410
+ get height(): number;
1411
+ /**
1412
+ * Current pointer (mouse or touch) X position in **canvas/screen space**,
1413
+ * in pixels. Updated every `mousemove` / `touchmove` event.
1414
+ * `(0, 0)` is the top-left corner of the canvas.
1415
+ * To convert to world space: `worldX = game.pointerX + game.scrollX`.
1416
+ *
1417
+ * On a touch screen the pointer is one finger: the first to touch while no
1418
+ * finger is followed. Other fingers never move it, and when the followed
1419
+ * finger lifts, the pointer stays where it left the screen even if others
1420
+ * are still down. Use {@link Game.getPointers} to follow several fingers.
1421
+ */
1422
+ get pointerX(): number;
1423
+ /**
1424
+ * Current pointer (mouse or touch) Y position in **canvas/screen space**,
1425
+ * in pixels. Updated every `mousemove` / `touchmove` event.
1426
+ * `(0, 0)` is the top-left corner of the canvas.
1427
+ * To convert to world space: `worldY = game.pointerY + game.scrollY`.
1428
+ */
1429
+ get pointerY(): number;
1430
+ /**
1431
+ * Registers a {@link Sprite} (or subclass instance) with the engine.
1432
+ *
1433
+ * After calling `add`, the sprite is rendered and, if dynamic
1434
+ * (`isStatic = false`), receives built-in velocity/gravity integration every
1435
+ * frame until {@link Game.destroySprite} or {@link Game.reset} is called.
1436
+ *
1437
+ * **Ownership:** The game instance takes ownership of the sprite from this
1438
+ * point forward. It will appear in {@link Game.getSprites} on the same frame.
1439
+ *
1440
+ * **Subclasses:** Any class that extends {@link Sprite} can be passed here.
1441
+ * The engine stores and processes it as a live sprite; your custom properties
1442
+ * are preserved on the instance.
1443
+ *
1444
+ * @param sprite - A {@link Sprite} instance (or subclass) to add.
1445
+ * @returns The same sprite instance, for chaining or inline assignment.
1446
+ *
1447
+ * @example
1448
+ * ```ts
1449
+ * // Plain sprite
1450
+ * const coin = new EmojiSprite("🪙", 300, 200, 32);
1451
+ * game.add(coin);
1452
+ *
1453
+ * // Custom subclass
1454
+ * class Enemy extends EmojiSprite {
1455
+ * speed = 150;
1456
+ * constructor(x: number, y: number) {
1457
+ * super("👾", x, y, 40);
1458
+ * }
1459
+ * }
1460
+ * const enemy = game.add(new Enemy(600, 100));
1461
+ * ```
1462
+ */
1463
+ add<T extends Sprite>(sprite: T): T;
1464
+ /**
1465
+ * Registers a {@link BackgroundLayer} with the engine.
1466
+ *
1467
+ * Background layers are rendered behind all sprites and are not affected by
1468
+ * physics, collisions, or sprite queries.
1469
+ *
1470
+ * @param layer - The background layer to add.
1471
+ * @returns The same background layer instance.
1472
+ *
1473
+ * @example
1474
+ * ```ts
1475
+ * const sky = game.addBackground(new BackgroundLayer("sky"));
1476
+ * sky.fit = "cover";
1477
+ * ```
1478
+ */
1479
+ addBackground(layer: BackgroundLayer): BackgroundLayer;
1480
+ /**
1481
+ * Removes a sprite from the engine, stopping its rendering and physics updates.
1482
+ * Also cancels any running animations targeting this sprite.
1483
+ *
1484
+ * **Side effects:** The sprite is removed immediately. Accessing the sprite's
1485
+ * fields after destruction has no effect on the engine, but reading them
1486
+ * returns stale values. Do not keep references to destroyed sprites.
1487
+ *
1488
+ * If `sprite` is not found (already destroyed or never added), this is a no-op.
1489
+ *
1490
+ * @param sprite - The sprite instance to destroy, as passed to {@link Game.add}.
1491
+ *
1492
+ * @example
1493
+ * ```ts
1494
+ * game.destroySprite(enemy); // remove enemy from game
1495
+ * ```
1496
+ */
1497
+ destroySprite(sprite: Sprite): void;
1498
+ /**
1499
+ * Removes a background layer from the engine.
1500
+ *
1501
+ * If the layer is not currently registered, this is a safe no-op.
1502
+ *
1503
+ * @param layer - The background layer to remove.
1504
+ */
1505
+ destroyBackgroundLayer(layer: BackgroundLayer): void;
1506
+ /**
1507
+ * Returns a **read-only snapshot** of all currently active sprites.
1508
+ * The array is a shallow copy — mutating it has no effect on the engine.
1509
+ * Individual sprite objects in the array are the live instances.
1510
+ *
1511
+ * **Deterministic guarantee:** Sprites appear in creation order within each
1512
+ * layer. The order matches the render order (lower layer = earlier in array).
1513
+ *
1514
+ * @returns A read-only array of active {@link Sprite} instances.
1515
+ *
1516
+ * @example
1517
+ * ```ts
1518
+ * const enemies = game.getSprites().filter(s => s.sprite === "👾");
1519
+ * ```
1520
+ */
1521
+ getSprites(): readonly Sprite[];
1522
+ /**
1523
+ * Returns a read-only snapshot of all active background layers.
1524
+ *
1525
+ * Background layers are returned in creation order within each layer value.
1526
+ */
1527
+ getBackgroundLayers(): readonly BackgroundLayer[];
1528
+ /**
1529
+ * Queues an image to be loaded during {@link Game.onPreload}.
1530
+ *
1531
+ * This method registers the asset only. The actual network/image fetch begins
1532
+ * after `onPreload` returns and is managed automatically by the engine.
1533
+ *
1534
+ * `loadImage` may only be called from within {@link Game.onPreload} or a
1535
+ * scene's {@link IScene.onPreload}.
1536
+ *
1537
+ * @param key - Stable key used later by {@link BackgroundLayer.imageKey} or {@link Game.getImage}.
1538
+ * @param src - Image URL or relative path.
1539
+ *
1540
+ * @example
1541
+ * ```ts
1542
+ * game.onPreload = () => {
1543
+ * game.loadImage("sky", "assets/sky.png");
1544
+ * };
1545
+ * ```
1546
+ */
1547
+ loadImage(key: string, src: string): void;
1548
+ /**
1549
+ * Queues an audio file to be loaded during {@link Game.onPreload}, to play
1550
+ * later with {@link Game.playSound}.
1551
+ *
1552
+ * Like {@link Game.loadImage}, it only registers the sound, and may only be
1553
+ * called from within {@link Game.onPreload} or a scene's
1554
+ * {@link IScene.onPreload}. The file loads and decodes with the images,
1555
+ * under the same loading line, and a file that fails is retried with them.
1556
+ * Keys are unique in the whole game: a sound cannot share its key with an
1557
+ * image. Prefer declaring sounds in an asset file, as `sound` entries
1558
+ * loaded with {@link Game.loadAssets}.
1559
+ *
1560
+ * MP3 plays in every browser; WAV does too, but its files are large. OGG
1561
+ * does not play in every Safari.
1562
+ *
1563
+ * @param key - Stable key used later by {@link Game.playSound}.
1564
+ * @param src - Audio file URL or relative path.
1565
+ *
1566
+ * @example
1567
+ * ```ts
1568
+ * game.onPreload = () => {
1569
+ * game.loadSound("jump", "assets/jump.mp3");
1570
+ * game.loadSound("theme", "assets/theme.mp3");
1571
+ * };
1572
+ * ```
1573
+ */
1574
+ loadSound(key: string, src: string): void;
1575
+ /**
1576
+ * Queues every asset an asset file declares, as one {@link Game.loadImage}
1577
+ * call per `image` entry and one {@link Game.loadSound} call per `sound`
1578
+ * entry would.
1579
+ *
1580
+ * Pass the content of a `*.assets.json` file, obtained by JSON import. The
1581
+ * file is checked with {@link parseAssetFile}, and an invalid one throws an
1582
+ * error naming what is wrong. Like `loadImage`, `loadAssets` may only be
1583
+ * called from within {@link Game.onPreload} or a scene's
1584
+ * {@link IScene.onPreload}.
1585
+ *
1586
+ * - Keys are unique in the whole game. A key that another asset file
1587
+ * declares, or that {@link Game.loadImage}, {@link Game.loadSound}, or
1588
+ * {@link Game.createTexture} registered, throws an error naming it, and so does a later
1589
+ * `loadImage` or `createTexture` of a key an asset file declares.
1590
+ * - Loading the same file again, as a scene's `onPreload()` does each time
1591
+ * the scene is entered, queues only its files that are not loaded.
1592
+ * - An entry of a type this engine does not support is skipped, with a
1593
+ * console warning naming it, so the game still loads every asset it can.
1594
+ *
1595
+ * @param assets - The content of a `*.assets.json` file. See {@link AssetFile}.
1596
+ *
1597
+ * @example
1598
+ * ```ts
1599
+ * import common from "./common.assets.json" with { type: "json" };
1600
+ *
1601
+ * game.onPreload = () => game.loadAssets(common);
1602
+ * ```
1603
+ */
1604
+ loadAssets(assets: unknown): void;
1605
+ /**
1606
+ * Creates a dynamic texture immediately and registers it under a stable key.
1607
+ *
1608
+ * Unlike {@link Game.loadImage}, this does not require {@link Game.onPreload}.
1609
+ * The `painter` callback receives a fresh offscreen canvas and should draw the
1610
+ * full texture contents into it.
1611
+ *
1612
+ * The resulting texture can be used anywhere a normal image key is accepted,
1613
+ * including {@link ImageSprite}, background layers, and optional modules.
1614
+ *
1615
+ * @param key - Stable texture key used later by sprites and render helpers.
1616
+ * @param width - Texture width in pixels. Minimum `1`.
1617
+ * @param height - Texture height in pixels. Minimum `1`.
1618
+ * @param painter - Function that paints into the offscreen texture canvas.
1619
+ *
1620
+ * @example
1621
+ * ```ts
1622
+ * game.createTexture("checkpoint", 128, 64, (ctx, canvas) => {
1623
+ * ctx.fillStyle = "#101820";
1624
+ * ctx.fillRect(0, 0, canvas.width, canvas.height);
1625
+ * ctx.fillStyle = "#ffd54f";
1626
+ * ctx.fillRect(8, 8, canvas.width - 16, canvas.height - 16);
1627
+ * });
1628
+ * ```
1629
+ */
1630
+ createTexture(key: string, width: number, height: number, painter: (ctx: CanvasRenderingContext2D, canvas: HTMLCanvasElement) => void): HTMLCanvasElement;
530
1631
  /**
531
- * Current pointer (mouse or touch) X position in **canvas/screen space**,
532
- * in pixels. Updated every `mousemove` / `touchmove` event.
533
- * `(0, 0)` is the top-left corner of the canvas.
534
- * To convert to world space: `worldX = game.pointerX + game.scrollX`.
1632
+ * Returns a loaded image or created texture previously registered with
1633
+ * {@link Game.loadImage} or {@link Game.createTexture}, or `undefined` if it
1634
+ * is not available.
535
1635
  */
536
- get pointerX(): number;
1636
+ getImage(key: string): HTMLImageElement | HTMLCanvasElement | undefined;
537
1637
  /**
538
- * Current pointer (mouse or touch) Y position in **canvas/screen space**,
539
- * in pixels. Updated every `mousemove` / `touchmove` event.
540
- * `(0, 0)` is the top-left corner of the canvas.
541
- * To convert to world space: `worldY = game.pointerY + game.scrollY`.
1638
+ * Returns `true` if a texture key is available.
542
1639
  */
543
- get pointerY(): number;
1640
+ hasImage(key: string): boolean;
544
1641
  /**
545
- * Registers a {@link Sprite} (or subclass instance) with the engine.
546
- * After calling `add`, the sprite is rendered and receives physics updates
547
- * every frame until {@link Game.destroySprite} or {@link Game.reset} is called.
1642
+ * Creates one runtime object from object data, such as a template found in
1643
+ * a {@link Design}, and adds it to the game.
548
1644
  *
549
- * **Ownership:** The game instance takes ownership of the sprite from this
550
- * point forward. It will appear in {@link Game.getSprites} on the same frame.
1645
+ * The object is built through the same public constructors and
1646
+ * {@link Game.add} or {@link Game.addBackground} that code uses, so it
1647
+ * behaves as the equivalent code. Its type picks its class: `image` builds
1648
+ * an {@link ImageSprite}, `emoji` an {@link EmojiSprite}, `text` a
1649
+ * {@link TextSprite}, and `background` a {@link BackgroundLayer}, unless a
1650
+ * builder registered with {@link Game.registerBuilderByTag} matches one of
1651
+ * its tags. Then every property the data holds is applied, including
1652
+ * `name`, `tags`, and a copy of `data`.
551
1653
  *
552
- * **Subclasses:** Any class that extends {@link Sprite} can be passed here.
553
- * The engine stores and processes it as a `Sprite`; your custom properties
554
- * are preserved on the instance.
1654
+ * Each call creates a new object, so one template can be created any number
1655
+ * of times. Set its position afterwards to place it; the object is never
1656
+ * drawn at the template's position.
555
1657
  *
556
- * @param sprite - A {@link Sprite} instance (or subclass) to add.
557
- * @returns The same sprite instance, for chaining or inline assignment.
1658
+ * Throws an error naming what is wrong when the data is not a valid design
1659
+ * object, or naming the key when it uses an image key that is not loaded.
1660
+ *
1661
+ * @param data - One design object, such as `design.findByName("player")`. Not a `Design`.
1662
+ * @param options - `add: false` creates the object without adding it to the game. Default: added.
1663
+ * @returns The created object. In TypeScript, name its type: `game.createObject<ImageSprite>(data)`.
558
1664
  *
559
1665
  * @example
560
1666
  * ```ts
561
- * // Plain sprite
562
- * const coin = new Sprite("🪙");
563
- * coin.x = 300; coin.y = 200; coin.size = 32;
564
- * game.add(coin);
1667
+ * import charactersJson from "./characters.design.json" with { type: "json" };
1668
+ * const characters = new Design(charactersJson);
565
1669
  *
566
- * // Custom subclass
567
- * class Enemy extends Sprite {
568
- * speed = 150;
569
- * constructor(x: number, y: number) {
570
- * super("👾");
571
- * this.x = x; this.y = y; this.size = 40;
572
- * }
573
- * }
574
- * const enemy = game.add(new Enemy(600, 100));
1670
+ * const bat = game.createObject(characters.findByName("bat"));
1671
+ * bat.x = spawn.x;
1672
+ * bat.y = spawn.y;
575
1673
  * ```
576
1674
  */
577
- add(sprite: Sprite): Sprite;
1675
+ createObject<T extends Sprite | BackgroundLayer = Sprite | BackgroundLayer>(data: DesignObject, options?: {
1676
+ add?: boolean;
1677
+ }): T;
578
1678
  /**
579
- * Removes a sprite from the engine, stopping its rendering and physics updates.
580
- * Also cancels any running animations targeting this sprite.
581
- *
582
- * **Side effects:** The sprite is removed immediately. Accessing the sprite's
583
- * fields after destruction has no effect on the engine, but reading them
584
- * returns stale values. Do not keep references to destroyed sprites.
1679
+ * Creates a runtime object from each object data, in order, and adds them
1680
+ * to the game, as {@link Game.createObject} does for one. Objects in the
1681
+ * same layer draw in the order of the data.
585
1682
  *
586
- * If `sprite` is not found (already destroyed or never added), this is a no-op.
1683
+ * Every object is checked before any is created, so invalid data or an
1684
+ * image key that is not loaded creates nothing.
587
1685
  *
588
- * @param sprite - The sprite instance to destroy, as passed to {@link Game.add}.
1686
+ * @param objects - Object data, such as `design.objects` or `design.findAllByTag("enemy")`. Not a `Design`.
1687
+ * @param options - `add: false` creates the objects without adding them to the game. Default: added.
1688
+ * @returns An {@link ObjectList} of the created objects, to find them by name or tag.
589
1689
  *
590
1690
  * @example
591
1691
  * ```ts
592
- * game.destroySprite(enemy); // remove enemy from game
1692
+ * import menuJson from "./menu.design.json" with { type: "json" };
1693
+ * const menu = new Design(menuJson);
1694
+ *
1695
+ * class MenuScene {
1696
+ * onCreate() {
1697
+ * const ui = game.createObjectList(menu.objects);
1698
+ * this.play = ui.findByName("play");
1699
+ * }
1700
+ * onUpdate() {
1701
+ * if (game.isPointerPressedOverSprite(this.play)) start(this.play.data.action);
1702
+ * }
1703
+ * }
593
1704
  * ```
594
1705
  */
595
- destroySprite(sprite: Sprite): void;
1706
+ createObjectList(objects: readonly DesignObject[], options?: {
1707
+ add?: boolean;
1708
+ }): ObjectList;
596
1709
  /**
597
- * Returns a **read-only snapshot** of all currently active sprites.
598
- * The array is a shallow copy — mutating it has no effect on the engine.
599
- * Individual sprite objects in the array are the live instances.
600
- *
601
- * **Deterministic guarantee:** Sprites appear in creation order within each
602
- * layer. The order matches the render order (lower layer = earlier in array).
603
- *
604
- * @returns A read-only array of active {@link Sprite} instances.
1710
+ * Makes {@link Game.createObject} and {@link Game.createObjectList} build
1711
+ * the design objects tagged `tag` with `builder`, such as an `Enemy` class
1712
+ * of the game's own.
1713
+ *
1714
+ * - The builder returns an instance of the object's type class or a
1715
+ * subclass of it: {@link ImageSprite} for `image`, {@link EmojiSprite} for
1716
+ * `emoji`, {@link TextSprite} for `text`, and {@link BackgroundLayer} for
1717
+ * `background`. Anything else throws an error naming the object.
1718
+ * - The engine then applies every property the data holds, so the file wins
1719
+ * over the constructor. Properties the data omits keep what the builder set.
1720
+ * An `emoji` object's `size` cannot be changed after construction, so a
1721
+ * builder must pass it on, or the creation throws.
1722
+ * - An object matching the builders of two of its tags throws an error
1723
+ * naming the object and both tags.
1724
+ * - Builders are scene state: {@link Game.reset} clears them, as it clears
1725
+ * timers, so each scene registers its own in `onCreate()`.
1726
+ *
1727
+ * @param tag - The tag whose objects the builder builds.
1728
+ * @param builder - Receives the object's data and the game, and returns the object, not yet added.
605
1729
  *
606
1730
  * @example
607
1731
  * ```ts
608
- * const enemies = game.getSprites().filter(s => s.sprite === "👾");
1732
+ * class Enemy extends ImageSprite {
1733
+ * update(dt) { this.x += this.data.speed * dt; }
1734
+ * }
1735
+ *
1736
+ * class Level1Scene {
1737
+ * onCreate() {
1738
+ * game.registerBuilderByTag("enemy", (obj, game) => new Enemy(game, obj.imageKey));
1739
+ * this.enemies = game.createObjectList(level1.findAllByTag("enemy")).objects;
1740
+ * }
1741
+ * }
609
1742
  * ```
610
1743
  */
611
- getSprites(): readonly Sprite[];
1744
+ registerBuilderByTag(tag: string, builder: ObjectBuilder): void;
612
1745
  /**
613
1746
  * Tests whether two sprites overlap using **Axis-Aligned Bounding Box (AABB)**
614
1747
  * collision detection.
615
1748
  *
616
1749
  * Each sprite's bounding box is a square centered at `(x, y)` with side
617
- * length `size`. Rotation is **ignored** — the box is always axis-aligned.
1750
+ * length `displaySize`. Rotation is **ignored** — the box is always axis-aligned.
618
1751
  *
619
1752
  * **No collision resolution is performed.** This method is detection-only.
620
- * If you need bounce or push-apart behavior, implement it in `onUpdate`.
1753
+ * Use {@link Game.collide} for the engine's basic explicit push-out helper.
621
1754
  *
622
1755
  * @param a - First sprite.
623
1756
  * @param b - Second sprite.
@@ -641,7 +1774,7 @@ export declare class Game {
641
1774
  *
642
1775
  * @param listA - First group of sprites.
643
1776
  * @param listB - Second group of sprites. May share sprites with `listA`.
644
- * @returns A `[Sprite, Sprite]` tuple of the first overlapping pair,
1777
+ * @returns A `[EmojiSprite, EmojiSprite]` tuple of the first overlapping pair,
645
1778
  * or `null` if no pair overlaps.
646
1779
  *
647
1780
  * @example
@@ -655,6 +1788,57 @@ export declare class Game {
655
1788
  * ```
656
1789
  */
657
1790
  overlapAny(listA: Sprite[], listB: Sprite[]): [Sprite, Sprite] | null;
1791
+ /**
1792
+ * Tests and resolves a basic AABB collision between two sprites.
1793
+ *
1794
+ * This helper is intended for simple platformer-style collision response.
1795
+ * It uses the same axis-aligned square bounds as {@link Game.overlap}, but
1796
+ * additionally pushes one sprite out of the collision and zeroes velocity on
1797
+ * the resolved axis.
1798
+ *
1799
+ * **Resolution rules:**
1800
+ * - If the first sprite is dynamic (`isStatic = false`), the first sprite is resolved.
1801
+ * - Otherwise, if the second sprite is dynamic, the second sprite is resolved.
1802
+ * - If both sprites are static, collision is reported but no movement occurs.
1803
+ *
1804
+ * The returned flags are always reported relative to the **first** sprite.
1805
+ *
1806
+ * @param a - First sprite. Usually the moving actor (for example, the player).
1807
+ * @param b - Second sprite. Usually a static obstacle or platform.
1808
+ * @returns Collision details, or `null` if the sprites do not overlap.
1809
+ * @throws Error if the game's physics helpers are not enabled.
1810
+ *
1811
+ * @example
1812
+ * ```ts
1813
+ * const hit = game.collide(player, floorTile);
1814
+ * if (hit?.grounded) {
1815
+ * canJump = true;
1816
+ * }
1817
+ * ```
1818
+ */
1819
+ collide(a: Sprite, b: Sprite): CollisionInfo | null;
1820
+ /**
1821
+ * Tests and resolves the first collision found between two groups of sprites.
1822
+ *
1823
+ * This behaves like {@link Game.overlapAny}, but uses the explicit collision
1824
+ * rules from {@link Game.collide} and returns the collision details as the
1825
+ * third tuple item.
1826
+ *
1827
+ * @param listA - First group of sprites.
1828
+ * @param listB - Second group of sprites.
1829
+ * @returns A `[EmojiSprite, EmojiSprite, CollisionInfo]` tuple for the first collision found,
1830
+ * or `null` if no pair overlaps.
1831
+ * @throws Error if the game's physics helpers are not enabled.
1832
+ *
1833
+ * @example
1834
+ * ```ts
1835
+ * const hit = game.collideAny([player], floorTiles);
1836
+ * if (hit?.[2].grounded) {
1837
+ * canJump = true;
1838
+ * }
1839
+ * ```
1840
+ */
1841
+ collideAny(listA: Sprite[], listB: Sprite[]): [Sprite, Sprite, CollisionInfo] | null;
658
1842
  /**
659
1843
  * Returns `true` while the specified key is held down (every frame it is held).
660
1844
  * Use this for continuous actions like movement.
@@ -695,6 +1879,8 @@ export declare class Game {
695
1879
  * Use this for continuous pointer actions.
696
1880
  *
697
1881
  * **Hold behavior:** returns `true` every frame from press until release.
1882
+ * On a touch screen it follows one finger, as {@link Game.pointerX} does,
1883
+ * so it turns `false` when that finger lifts, even if another is down.
698
1884
  *
699
1885
  * @returns `true` if the pointer is currently pressed.
700
1886
  *
@@ -723,50 +1909,50 @@ export declare class Game {
723
1909
  * Returns `true` while any active pointer is held down over the target sprite.
724
1910
  * Works with both mouse input and multiple simultaneous touches.
725
1911
  *
726
- * Pointer hit testing uses a circular area centered on the sprite. The radius
727
- * is `sprite.size * radiusScale`. World-space sprites are tested against the
728
- * current camera scroll. HUD sprites with `ignoreScroll = true` are tested in
729
- * screen space.
1912
+ * Pointer hit testing uses the sprite's exact displayed rectangular bounds.
1913
+ * World-space sprites are tested against the current camera scroll. HUD
1914
+ * sprites with `ignoreScroll = true` are tested in screen space. For
1915
+ * anchored {@link TextSprite} instances, the engine first resolves
1916
+ * `anchorX` / `anchorY` into the final rendered center, then tests against
1917
+ * that rectangle.
730
1918
  *
731
1919
  * Use this for continuous virtual buttons such as touch movement controls.
732
1920
  *
733
1921
  * @param sprite - Target sprite to test. If `null` / `undefined`, returns `false`.
734
- * @param radiusScale - Multiplier applied to `sprite.size` to define the hit radius.
735
- * Default: `0.5`.
736
1922
  * @returns `true` if any currently held pointer overlaps the sprite hit area.
737
1923
  *
738
1924
  * @example
739
1925
  * ```ts
740
- * if (game.isPointerDownOverSprite(leftButton, 0.72)) {
1926
+ * if (game.isPointerDownOverSprite(leftButton)) {
741
1927
  * player.x -= 200 * dt;
742
1928
  * }
743
1929
  * ```
744
1930
  */
745
- isPointerDownOverSprite(sprite: Sprite | null | undefined, radiusScale?: number): boolean;
1931
+ isPointerDownOverSprite(sprite: Sprite | null | undefined): boolean;
746
1932
  /**
747
1933
  * Returns `true` only on the frame any pointer first pressed over the target
748
1934
  * sprite. Works with both mouse input and multiple simultaneous touches.
749
1935
  *
750
- * Pointer hit testing uses a circular area centered on the sprite. The radius
751
- * is `sprite.size * radiusScale`. World-space sprites are tested against the
752
- * current camera scroll. HUD sprites with `ignoreScroll = true` are tested in
753
- * screen space.
1936
+ * Pointer hit testing uses the sprite's exact displayed rectangular bounds.
1937
+ * World-space sprites are tested against the current camera scroll. HUD
1938
+ * sprites with `ignoreScroll = true` are tested in screen space. For
1939
+ * anchored {@link TextSprite} instances, the engine first resolves
1940
+ * `anchorX` / `anchorY` into the final rendered center, then tests against
1941
+ * that rectangle.
754
1942
  *
755
1943
  * Use this for one-shot virtual buttons such as menu taps.
756
1944
  *
757
1945
  * @param sprite - Target sprite to test. If `null` / `undefined`, returns `false`.
758
- * @param radiusScale - Multiplier applied to `sprite.size` to define the hit radius.
759
- * Default: `0.5`.
760
1946
  * @returns `true` if any pointer began pressing this frame over the sprite hit area.
761
1947
  *
762
1948
  * @example
763
1949
  * ```ts
764
- * if (game.isPointerPressedOverSprite(startButton, 0.8)) {
1950
+ * if (game.isPointerPressedOverSprite(startButton)) {
765
1951
  * startGame();
766
1952
  * }
767
1953
  * ```
768
1954
  */
769
- isPointerPressedOverSprite(sprite: Sprite | null | undefined, radiusScale?: number): boolean;
1955
+ isPointerPressedOverSprite(sprite: Sprite | null | undefined): boolean;
770
1956
  /**
771
1957
  * Returns a read-only snapshot of all currently active pointers.
772
1958
  *
@@ -784,7 +1970,7 @@ export declare class Game {
784
1970
  * const pointers = game.getPointers();
785
1971
  * if (pointers.length > 0) {
786
1972
  * const first = pointers[0];
787
- * game.text(`Pointer: ${first.x}, ${first.y}`, 10, 10);
1973
+ * game.drawText(`Pointer: ${first.x}, ${first.y}`, 10, 10, 14);
788
1974
  * }
789
1975
  * ```
790
1976
  */
@@ -793,29 +1979,29 @@ export declare class Game {
793
1979
  * Returns a read-only snapshot of all active pointers currently overlapping
794
1980
  * the target sprite.
795
1981
  *
796
- * Pointer hit testing uses a circular area centered on the sprite. The radius
797
- * is `sprite.size * radiusScale`. World-space sprites are tested against the
798
- * current camera scroll. HUD sprites with `ignoreScroll = true` are tested in
799
- * screen space.
1982
+ * Pointer hit testing uses the sprite's exact displayed rectangular bounds.
1983
+ * World-space sprites are tested against the current camera scroll. HUD
1984
+ * sprites with `ignoreScroll = true` are tested in screen space. For
1985
+ * anchored {@link TextSprite} instances, the engine first resolves
1986
+ * `anchorX` / `anchorY` into the final rendered center, then tests against
1987
+ * that rectangle.
800
1988
  *
801
1989
  * Use this when you need more than a boolean result, such as reading the exact
802
1990
  * pointer position over a virtual joystick or draggable control.
803
1991
  *
804
1992
  * @param sprite - Target sprite to test. If `null` / `undefined`, returns an empty array.
805
- * @param radiusScale - Multiplier applied to `sprite.size` to define the hit radius.
806
- * Default: `0.5`.
807
1993
  * @returns A read-only array of active pointer snapshots currently over the sprite.
808
1994
  *
809
1995
  * @example
810
1996
  * ```ts
811
- * const touches = game.getPointersOverSprite(joystickBase, 1.0);
1997
+ * const touches = game.getPointersOverSprite(joystickBase);
812
1998
  * if (touches.length > 0) {
813
1999
  * const p = touches[0];
814
2000
  * const dx = p.x - joystickBase.x;
815
2001
  * }
816
2002
  * ```
817
2003
  */
818
- getPointersOverSprite(sprite: Sprite | null | undefined, radiusScale?: number): readonly PointerInfo[];
2004
+ getPointersOverSprite(sprite: Sprite | null | undefined): readonly PointerInfo[];
819
2005
  /**
820
2006
  * Returns `true` when the current device appears to be mobile/touch-first.
821
2007
  *
@@ -835,16 +2021,64 @@ export declare class Game {
835
2021
  * ```
836
2022
  */
837
2023
  isMobileDevice(): boolean;
2024
+ /**
2025
+ * Plays a sound loaded with {@link Game.loadSound} or an asset file's
2026
+ * `sound` entry, and returns its {@link SoundPlayback}.
2027
+ *
2028
+ * Plays overlap: playing a sound that is already playing starts another
2029
+ * play of it. Keep the returned playback to pause, resume, or stop it, such
2030
+ * as the game's music. A one-shot play stops by itself when it ends; a
2031
+ * looping one plays until stopped.
2032
+ *
2033
+ * - **Before the first tap.** Browsers keep a page silent until the player
2034
+ * taps, clicks, or presses a key. A looping sound started earlier, such as
2035
+ * music started in a scene's `onCreate()`, waits and begins with that
2036
+ * first gesture. A one-shot sound played earlier is dropped, and its
2037
+ * playback is returned already stopped.
2038
+ * - **Scenes.** {@link Game.reset} and {@link Game.transitionTo} do not stop
2039
+ * sounds. Stop the music yourself when a scene should change it.
2040
+ * - **Hidden page.** Every sound pauses while the page is hidden, and
2041
+ * continues when it is shown again.
2042
+ *
2043
+ * Throws an error naming the key when no sound is loaded under it.
2044
+ *
2045
+ * @param key - A key loaded with {@link Game.loadSound} or an asset file.
2046
+ * @param options - `loop` to repeat until stopped, and `volume` from `0` to `1`.
2047
+ *
2048
+ * @example
2049
+ * ```ts
2050
+ * game.playSound("jump");
2051
+ * const music = game.playSound("theme", { loop: true, volume: 0.6 });
2052
+ * music.pause();
2053
+ * music.resume();
2054
+ * music.stop();
2055
+ * ```
2056
+ */
2057
+ playSound(key: string, options?: PlaySoundOptions): SoundPlayback;
2058
+ /**
2059
+ * Stops every sound playing from a file, such as music and effects started
2060
+ * with {@link Game.playSound}. Synthesized tones are not affected.
2061
+ *
2062
+ * @example
2063
+ * ```ts
2064
+ * game.stopAllSounds();
2065
+ * ```
2066
+ */
2067
+ stopAllSounds(): void;
838
2068
  /**
839
2069
  * Plays a square-wave beep using the Web Audio API.
840
2070
  *
841
- * **Square wave only.** MinimoJS does not support audio files, samples,
842
- * or other waveforms. Only procedural square-wave tones.
2071
+ * **Square wave only.** This synthesizes a tone and needs no file. To play
2072
+ * a recorded sound, load it with {@link Game.loadSound} and play it with
2073
+ * {@link Game.playSound}.
843
2074
  *
844
2075
  * The AudioContext is created lazily on first call. Browsers require a user
845
2076
  * gesture (click, keypress) before audio can play — always call `sound()` in
846
2077
  * response to user input or a game event triggered by input.
847
2078
  *
2079
+ * If you need a melody/sequence, use {@link Game.soundSequence} instead of
2080
+ * multiple `sound()` calls in the same frame.
2081
+ *
848
2082
  * The tone fades out exponentially over `durationMs` to avoid clicks.
849
2083
  *
850
2084
  * @param freq - Frequency in Hz. Middle C = 261.6. Typical range: 100–4000 Hz.
@@ -858,6 +2092,20 @@ export declare class Game {
858
2092
  * ```
859
2093
  */
860
2094
  sound(freq: number, durationMs: number): void;
2095
+ /**
2096
+ * Plays multiple square-wave tones in strict sequence.
2097
+ *
2098
+ * Each tuple is `[frequencyHz, durationMs]`. The next tone starts when the
2099
+ * previous one ends.
2100
+ *
2101
+ * @param tones - Tone tuples in playback order.
2102
+ *
2103
+ * @example
2104
+ * ```ts
2105
+ * game.soundSequence([660, 80], [820, 90], [980, 110], [1180, 150]);
2106
+ * ```
2107
+ */
2108
+ soundSequence(...tones: Array<readonly [number, number]>): void;
861
2109
  /**
862
2110
  * Animates a sprite's {@link Sprite.alpha} from its current value to `to`
863
2111
  * over `durationMs` milliseconds using **linear interpolation**.
@@ -906,6 +2154,289 @@ export declare class Game {
906
2154
  * ```
907
2155
  */
908
2156
  animateRotation(sprite: Sprite, to: number, durationMs: number, onComplete?: () => void): void;
2157
+ /**
2158
+ * Animates a sprite's visual deformation using non-uniform scaling around a
2159
+ * normalized pivot point.
2160
+ *
2161
+ * This affects rendering only. Physics and collision bounds continue to use
2162
+ * {@link EmojiSprite.displaySize} and ignore the deform result.
2163
+ *
2164
+ * `pivotX` / `pivotY` are normalized anchors in the sprite's square display box:
2165
+ * - `0` = left/top
2166
+ * - `0.5` = center
2167
+ * - `1` = right/bottom
2168
+ *
2169
+ * For example, `pivotY = 1` keeps the bottom visually pinned while squashing
2170
+ * or stretching, which is useful for floor-contact animation.
2171
+ *
2172
+ * Like other MinimoJS animations, this animates from the sprite's current
2173
+ * deform state to the requested target and leaves the final result applied.
2174
+ *
2175
+ * @param sprite - The sprite to deform.
2176
+ * @param toScaleX - Target horizontal deform scale. `1` = unchanged.
2177
+ * @param toScaleY - Target vertical deform scale. `1` = unchanged.
2178
+ * @param pivotX - Horizontal pivot in normalized `[0, 1]` sprite space.
2179
+ * @param pivotY - Vertical pivot in normalized `[0, 1]` sprite space.
2180
+ * @param durationMs - Duration of the animation in **milliseconds**.
2181
+ * @param onComplete - Optional callback invoked when the animation finishes.
2182
+ *
2183
+ * @example
2184
+ * ```ts
2185
+ * game.animateDeform(player, 1.18, 0.85, 0.5, 1, 90, () => {
2186
+ * game.animateDeform(player, 1, 1, 0.5, 1, 120);
2187
+ * });
2188
+ * ```
2189
+ */
2190
+ animateDeform(sprite: Sprite, toScaleX: number, toScaleY: number, pivotX: number, pivotY: number, durationMs: number, onComplete?: () => void): void;
2191
+ /**
2192
+ * Convenience helper that squashes a sprite around its horizontal center.
2193
+ *
2194
+ * This is equivalent to animating toward a wider, shorter visual pose using
2195
+ * {@link Game.animateDeform}. `pivotY = 1` is the common floor-anchored case.
2196
+ *
2197
+ * @param sprite - The sprite to squash.
2198
+ * @param pivotY - Vertical pivot in normalized `[0, 1]` sprite space.
2199
+ * @param durationMs - Duration of the animation in **milliseconds**.
2200
+ * @param onComplete - Optional callback invoked when the animation finishes.
2201
+ */
2202
+ animateSquash(sprite: Sprite, pivotY: number, durationMs: number, onComplete?: () => void): void;
2203
+ /**
2204
+ * Convenience helper that stretches a sprite around its horizontal center.
2205
+ *
2206
+ * This is equivalent to animating toward a narrower, taller visual pose using
2207
+ * {@link Game.animateDeform}. `pivotY = 1` is the common floor-anchored case.
2208
+ *
2209
+ * @param sprite - The sprite to stretch.
2210
+ * @param pivotY - Vertical pivot in normalized `[0, 1]` sprite space.
2211
+ * @param durationMs - Duration of the animation in **milliseconds**.
2212
+ * @param onComplete - Optional callback invoked when the animation finishes.
2213
+ */
2214
+ animateStretch(sprite: Sprite, pivotY: number, durationMs: number, onComplete?: () => void): void;
2215
+ /**
2216
+ * Convenience helper that applies a centered uniform scale pulse and then
2217
+ * returns the sprite to its neutral shape.
2218
+ *
2219
+ * Internally this runs two deform animations back-to-back using
2220
+ * {@link Game.animateDeform}.
2221
+ *
2222
+ * @param sprite - The sprite to pulse.
2223
+ * @param scale - Peak uniform scale reached midway through the pulse. `1` leaves the sprite unchanged.
2224
+ * @param durationMs - Total pulse duration in **milliseconds**.
2225
+ * @param onComplete - Optional callback invoked after the sprite returns to neutral.
2226
+ *
2227
+ * @example
2228
+ * ```ts
2229
+ * game.animatePulse(coin, 1.25, 220);
2230
+ * ```
2231
+ */
2232
+ animatePulse(sprite: Sprite, scale: number, durationMs: number, onComplete?: () => void): void;
2233
+ /**
2234
+ * Applies a decaying screen-space shake to a sprite without changing its
2235
+ * logical position.
2236
+ *
2237
+ * This is a render-only effect. Physics, collisions, and the sprite's
2238
+ * `x` / `y` values are not modified.
2239
+ *
2240
+ * @param sprite - The sprite to shake.
2241
+ * @param intensity - Maximum shake offset in pixels.
2242
+ * @param durationMs - Duration of the shake in **milliseconds**.
2243
+ * @param onComplete - Optional callback invoked when the shake ends.
2244
+ *
2245
+ * @example
2246
+ * ```ts
2247
+ * game.animateShake(player, 18, 300);
2248
+ * ```
2249
+ */
2250
+ animateShake(sprite: Sprite, intensity: number, durationMs: number, onComplete?: () => void): void;
2251
+ /**
2252
+ * Moves a sprite upward and back down to its starting position along a simple
2253
+ * parabolic arc.
2254
+ *
2255
+ * This animation writes directly to {@link Sprite.x} / {@link Sprite.y} while
2256
+ * it is active.
2257
+ *
2258
+ * @param sprite - The sprite to bounce.
2259
+ * @param height - Peak bounce height in pixels.
2260
+ * @param durationMs - Total bounce duration in **milliseconds**.
2261
+ * @param onComplete - Optional callback invoked when the bounce ends.
2262
+ *
2263
+ * @example
2264
+ * ```ts
2265
+ * game.animateBounce(ball, 120, 600);
2266
+ * ```
2267
+ */
2268
+ animateBounce(sprite: Sprite, height: number, durationMs: number, onComplete?: () => void): void;
2269
+ /**
2270
+ * Moves a sprite upward and back down with a smooth sine-shaped float motion.
2271
+ *
2272
+ * This animation writes directly to {@link Sprite.x} / {@link Sprite.y} while
2273
+ * it is active.
2274
+ *
2275
+ * @param sprite - The sprite to float.
2276
+ * @param distance - Maximum upward travel in pixels.
2277
+ * @param durationMs - Total float duration in **milliseconds**.
2278
+ * @param onComplete - Optional callback invoked when the float ends.
2279
+ *
2280
+ * @example
2281
+ * ```ts
2282
+ * game.animateFloat(balloon, 90, 1200);
2283
+ * ```
2284
+ */
2285
+ animateFloat(sprite: Sprite, distance: number, durationMs: number, onComplete?: () => void): void;
2286
+ /**
2287
+ * Toggles a sprite's rendered opacity on and off a fixed number of times.
2288
+ *
2289
+ * This is a render-only effect. The sprite remains present in the world and
2290
+ * keeps receiving physics updates while blinking.
2291
+ *
2292
+ * @param sprite - The sprite to blink.
2293
+ * @param times - Number of visible/invisible toggle cycles.
2294
+ * @param durationMs - Total blink duration in **milliseconds**.
2295
+ * @param onComplete - Optional callback invoked when blinking ends.
2296
+ *
2297
+ * @example
2298
+ * ```ts
2299
+ * game.animateBlink(player, 4, 700);
2300
+ * ```
2301
+ */
2302
+ animateBlink(sprite: Sprite, times: number, durationMs: number, onComplete?: () => void): void;
2303
+ /**
2304
+ * Applies a rapid irregular alpha variation to create a damaged, unstable, or
2305
+ * ghost-like flicker.
2306
+ *
2307
+ * This is a render-only effect and does not change the sprite's logical
2308
+ * position or collision state.
2309
+ *
2310
+ * @param sprite - The sprite to flicker.
2311
+ * @param durationMs - Total flicker duration in **milliseconds**.
2312
+ * @param onComplete - Optional callback invoked when the flicker ends.
2313
+ *
2314
+ * @example
2315
+ * ```ts
2316
+ * game.animateFlicker(ghost, 900);
2317
+ * ```
2318
+ */
2319
+ animateFlicker(sprite: Sprite, durationMs: number, onComplete?: () => void): void;
2320
+ /**
2321
+ * Moves a sprite from its current position to a target position along a
2322
+ * parabolic arc.
2323
+ *
2324
+ * This animation writes directly to {@link Sprite.x} / {@link Sprite.y} while
2325
+ * it is active.
2326
+ *
2327
+ * @param sprite - The sprite to move.
2328
+ * @param toX - Destination X position in world space.
2329
+ * @param toY - Destination Y position in world space.
2330
+ * @param arcHeight - Maximum height of the arc above the linear path, in pixels.
2331
+ * @param durationMs - Total arc duration in **milliseconds**.
2332
+ * @param onComplete - Optional callback invoked when the arc ends.
2333
+ *
2334
+ * @example
2335
+ * ```ts
2336
+ * game.animateArc(coin, player.x, player.y, 80, 420);
2337
+ * ```
2338
+ */
2339
+ animateArc(sprite: Sprite, toX: number, toY: number, arcHeight: number, durationMs: number, onComplete?: () => void): void;
2340
+ /**
2341
+ * Emits temporary afterimages from a sprite to create a motion trail.
2342
+ *
2343
+ * This is a render-only effect. Trail ghosts are not real sprites and do not
2344
+ * appear in {@link Game.getSprites}, collide, or receive physics.
2345
+ *
2346
+ * @param sprite - The sprite to sample for trail ghosts.
2347
+ * @param options - Optional trail tuning values.
2348
+ * @param onComplete - Optional callback invoked when the emitter stops spawning ghosts.
2349
+ *
2350
+ * @example
2351
+ * ```ts
2352
+ * game.animateTrail(player, { durationMs: 300, spacingMs: 30, fadeMs: 180 });
2353
+ * ```
2354
+ */
2355
+ animateTrail(sprite: Sprite, options?: TrailOptions, onComplete?: () => void): void;
2356
+ /**
2357
+ * Breaks a sprite into visual pieces that burst outward from its current
2358
+ * rendered appearance.
2359
+ *
2360
+ * This is a render-only effect. The spawned pieces are not real sprites and do
2361
+ * not appear in {@link Game.getSprites}, receive physics, or collide.
2362
+ *
2363
+ * By default, the original sprite is destroyed immediately after the explosion
2364
+ * effect is spawned. Set `destroySprite: false` to hide the sprite during the
2365
+ * effect and restore it when the explosion ends.
2366
+ *
2367
+ * @param sprite - The sprite to explode.
2368
+ * @param options - Optional explosion tuning values.
2369
+ * @param onComplete - Optional callback invoked when the effect finishes.
2370
+ *
2371
+ * @example
2372
+ * ```ts
2373
+ * game.animateExplode(enemy, { rows: 4, cols: 4, durationMs: 650, speed: 320 });
2374
+ * ```
2375
+ */
2376
+ animateExplode(sprite: Sprite, options?: ExplodeOptions, onComplete?: () => void): void;
2377
+ /**
2378
+ * Spawns visual pieces around a sprite and converges them back into its
2379
+ * current rendered appearance.
2380
+ *
2381
+ * This is a render-only effect. The spawned pieces are not real sprites and
2382
+ * do not appear in {@link Game.getSprites}, receive physics, or collide.
2383
+ *
2384
+ * The original sprite is hidden while the assembly plays and is restored when
2385
+ * the effect finishes.
2386
+ *
2387
+ * @param sprite - The sprite to assemble.
2388
+ * @param options - Optional assembly tuning values.
2389
+ * @param onComplete - Optional callback invoked when the effect finishes.
2390
+ */
2391
+ animateAssemble(sprite: Sprite, options?: AssembleOptions, onComplete?: () => void): void;
2392
+ /**
2393
+ * Breaks a sprite apart locally inside its own bounds using a directional
2394
+ * dissolve sweep.
2395
+ *
2396
+ * This is a render-only effect. The spawned pieces are not real sprites and
2397
+ * do not appear in {@link Game.getSprites}, receive physics, or collide.
2398
+ *
2399
+ * By default, the original sprite is destroyed immediately after the effect
2400
+ * is spawned. Set `destroySprite: false` to leave the sprite hidden instead.
2401
+ *
2402
+ * @param sprite - The sprite to disintegrate.
2403
+ * @param options - Optional disintegration tuning values.
2404
+ * @param onComplete - Optional callback invoked when the effect finishes.
2405
+ */
2406
+ animateDisintegrate(sprite: Sprite, options?: DisintegrateOptions, onComplete?: () => void): void;
2407
+ /**
2408
+ * Reconstructs a sprite locally inside its own bounds using a directional
2409
+ * integration sweep.
2410
+ *
2411
+ * This is a render-only effect. The spawned pieces are not real sprites and
2412
+ * do not appear in {@link Game.getSprites}, receive physics, or collide.
2413
+ *
2414
+ * The original sprite is hidden while the integration plays and is restored
2415
+ * when the effect finishes.
2416
+ *
2417
+ * @param sprite - The sprite to integrate.
2418
+ * @param options - Optional integration tuning values.
2419
+ * @param onComplete - Optional callback invoked when the effect finishes.
2420
+ */
2421
+ animateIntegrate(sprite: Sprite, options?: IntegrateOptions, onComplete?: () => void): void;
2422
+ /**
2423
+ * Reveals or covers a sprite with a directional wipe mask.
2424
+ *
2425
+ * This is a render-only effect that captures the sprite's current appearance
2426
+ * and animates a clipping region over that snapshot.
2427
+ *
2428
+ * For `mode: "reveal"`, the original sprite is hidden during the wipe and is
2429
+ * restored when the effect finishes.
2430
+ *
2431
+ * For `mode: "cover"`, the effect hides the sprite over time. If
2432
+ * `destroySprite` is omitted or `true`, the sprite is destroyed immediately
2433
+ * after the wipe starts and only the wipe snapshot remains visible.
2434
+ *
2435
+ * @param sprite - The sprite to wipe.
2436
+ * @param options - Optional wipe tuning values.
2437
+ * @param onComplete - Optional callback invoked when the effect finishes.
2438
+ */
2439
+ animateWipe(sprite: Sprite, options?: WipeOptions, onComplete?: () => void): void;
909
2440
  /**
910
2441
  * Schedules a callback to fire after `delayMs` milliseconds, driven by the
911
2442
  * rAF loop (not `setTimeout`). Timers accumulate elapsed time each frame and
@@ -952,18 +2483,26 @@ export declare class Game {
952
2483
  */
953
2484
  clearTimer(id: number): void;
954
2485
  /**
955
- * Draws text on screen as a **screen-space overlay** this frame.
2486
+ * Draws text on screen as a **simple screen-space overlay** this frame.
956
2487
  *
957
2488
  * **Overlay behavior:** Text is drawn in canvas/screen space — it ignores
958
2489
  * `scrollX` / `scrollY`. Position `(0, 0)` is always the top-left of the canvas.
959
- * Use this for HUD elements: score, lives, timer, debug info.
2490
+ * Use this for lightweight HUD elements: score, lives, timer, debug info.
960
2491
  *
961
2492
  * **Per-frame:** `drawText` must be called every frame to keep text visible.
962
2493
  * The text overlay list is cleared after each render. Call this inside `onUpdate`.
963
2494
  *
964
2495
  * **Layer:** Text is always drawn on top of all sprites.
965
- * **Font:** Text always uses a fixed `monospace` font family.
966
- * Font family cannot be customized in MinimoJS v1.
2496
+ * **Font:** Text always uses `monospace`. Use {@link TextSprite} for any
2497
+ * other family.
2498
+ *
2499
+ * Prefer {@link TextSprite} for UI buttons or labels that need persistent
2500
+ * bounds, hit testing, fixed sizes, backgrounds, borders, or text stroke.
2501
+ * `drawText()` is the lightweight overlay API, not the primary UI API.
2502
+ *
2503
+ * For controls that are only a single emoji, prefer {@link EmojiSprite} over
2504
+ * {@link TextSprite}. Emoji-only buttons do not benefit from text padding and
2505
+ * usually fit more naturally in the sprite pipeline.
967
2506
  *
968
2507
  * @param text - The string to render. Supports emoji and Unicode.
969
2508
  * @param x - X position in **screen space** (pixels from canvas left edge).
@@ -1000,6 +2539,25 @@ export declare class Game {
1000
2539
  * ```
1001
2540
  */
1002
2541
  clearSpriteCache(): void;
2542
+ /**
2543
+ * Registers a web font family that must be loaded before the first frame.
2544
+ *
2545
+ * Call this before {@link Game.start}, typically right after constructing the
2546
+ * game or inside {@link Game.onPreload}. MinimoJS waits for every registered
2547
+ * font via `document.fonts.load(...)` before rendering anything. Host
2548
+ * environments may also pre-register fonts by setting
2549
+ * `globalThis.__MINIMO_WEB_FONT_REQUIREMENTS__` before your game code runs.
2550
+ *
2551
+ * The font itself must still be declared by your page (for example with a
2552
+ * `<link rel="stylesheet">` in `index.html`). MinimoJS only waits for it.
2553
+ *
2554
+ * @example
2555
+ * ```ts
2556
+ * game.requireFont('"Press Start 2P"');
2557
+ * game.requireFont('"Bangers"', { weight: "700" });
2558
+ * ```
2559
+ */
2560
+ requireFont(family: string, options?: FontRequirementOptions): void;
1003
2561
  /**
1004
2562
  * Returns a pseudo-random floating-point number in the range `[0, 1)`.
1005
2563
  * Delegates to `Math.random()`.
@@ -1021,9 +2579,12 @@ export declare class Game {
1021
2579
  * Performs a full engine state reset to enable scene switching.
1022
2580
  *
1023
2581
  * **Cleared by reset:**
2582
+ * - All background layers
1024
2583
  * - All sprites (equivalent to calling {@link Game.destroySprite} on every sprite)
1025
2584
  * - All timers (regardless of repeat state)
1026
2585
  * - All running animations
2586
+ * - All active explosion effects
2587
+ * - All active trail effects
1027
2588
  * - All pending text overlays
1028
2589
  * - Scroll position (`scrollX = 0`, `scrollY = 0`)
1029
2590
  * - Per-frame input state (pressed keys, pressed pointer)
@@ -1036,50 +2597,95 @@ export declare class Game {
1036
2597
  * - Canvas dimensions
1037
2598
  * - AudioContext
1038
2599
  *
1039
- * After clearing, `reset()` immediately calls `onCreate()` so your callback
1040
- * can rebuild the new scene synchronously.
2600
+ * After clearing, `reset()` immediately calls the active scene's
2601
+ * `onCreate()` (or legacy {@link Game.onCreate} if no scene is active) so it
2602
+ * can rebuild synchronously.
2603
+ *
2604
+ * The exception is a scene whose {@link IScene.onPreload} registers images
2605
+ * that are not loaded yet. Then the current scene freezes and dims under a progress
2606
+ * ring, nothing is cleared until the images load, and `reset()` returns
2607
+ * before the scene is rebuilt; its `onCreate()` runs once they have loaded.
2608
+ * A `reset()` called while a scene is loading is ignored.
2609
+ *
2610
+ * @param scene - Optional new scene to make active before rebuilding.
1041
2611
  *
1042
2612
  * @example
1043
2613
  * ```ts
1044
- * // Switch from gameplay to game-over screen
1045
- * function gameOver() {
1046
- * game.reset(); // onCreate() is called here, rebuild inside it
1047
- * }
1048
- *
1049
- * game.onCreate = () => {
1050
- * // Scene init
1051
- * const skull = new Sprite("💀");
1052
- * skull.x = 400; skull.y = 300; skull.size = 96;
1053
- * game.add(skull);
1054
- * game.addTimer(3000, false, () => game.reset()); // auto-restart
1055
- * };
2614
+ * class GameOverScene {
2615
+ * onCreate() {
2616
+ * const skull = new EmojiSprite("💀", 400, 300, 96);
2617
+ * game.add(skull);
2618
+ * game.addTimer(3000, false, () => game.reset());
2619
+ * }
2620
+ * }
2621
+ *
2622
+ * game.reset(new GameOverScene());
1056
2623
  * ```
1057
2624
  */
1058
- reset(): void;
2625
+ reset(scene?: IScene): void;
2626
+ /**
2627
+ * Changes to a new scene using a full-screen transition between frozen scene
2628
+ * snapshots.
2629
+ *
2630
+ * `transitionTo()` does not change the behavior of {@link Game.reset}. It
2631
+ * captures the current scene as a snapshot, rebuilds the target scene
2632
+ * immediately, captures the new scene as another snapshot, and then animates
2633
+ * between those two images for the requested duration.
2634
+ *
2635
+ * While the transition is active, gameplay updates are paused.
2636
+ *
2637
+ * If the target scene's {@link IScene.onPreload} registers images that are
2638
+ * not loaded yet, the current scene first freezes and dims under a progress ring
2639
+ * until they load, and the transition plays after that. `transitionTo()`
2640
+ * then returns before the target scene exists; continue in its
2641
+ * `onCreate()` or in `onComplete`. If the player declines to retry failed
2642
+ * images, the game stays on the current scene and `onComplete` is not
2643
+ * called.
2644
+ *
2645
+ * A call made while a transition plays or a scene loads is ignored.
2646
+ *
2647
+ * If the game loop is not running yet, this falls back to
2648
+ * {@link Game.reset}.
2649
+ *
2650
+ * @param scene - Target scene to make active.
2651
+ * @param options - Transition style and optional tuning values.
2652
+ * @param onComplete - Optional callback invoked when the transition finishes.
2653
+ */
2654
+ transitionTo(scene: IScene, options: SceneTransitionOptions, onComplete?: () => void): void;
1059
2655
  /**
1060
2656
  * Starts the `requestAnimationFrame` game loop.
1061
2657
  * Safe to call multiple times — does nothing if already running.
1062
- * If this is the first start (or after a reset), `onCreate()` is called
1063
- * before the first frame.
1064
- *
1065
- * The loop calls `onUpdate` once per frame, then renders all sprites and
1066
- * text overlays. Order per frame:
2658
+ * On the first start, MinimoJS runs {@link Game.onPreload} and the active
2659
+ * scene's {@link IScene.onPreload}, loads the images they queued while
2660
+ * showing a thin loading line, and waits for all fonts registered via
2661
+ * {@link Game.requireFont}. After that, the active scene's `onCreate()` is
2662
+ * called before the first frame.
2663
+ *
2664
+ * The loop calls the active scene's `onUpdate(dt)` (or legacy
2665
+ * {@link Game.onUpdate}) once per frame, then renders all sprites and text
2666
+ * overlays. Order per frame:
1067
2667
  * 1. Accumulate timer elapsed time; fire ready callbacks.
1068
2668
  * 2. Advance animations (linear interpolation).
1069
- * 3. Apply gravity to sprite velocities.
1070
- * 4. Apply velocities to sprite positions.
1071
- * 5. Call `onUpdate(dt)`.
1072
- * 6. Render sprites (sorted by layer) with scroll offset.
1073
- * 7. Render text overlays (screen space, on top of sprites).
1074
- * 8. Clear per-frame input state.
2669
+ * 3. Advance active piece and wipe effects.
2670
+ * 4. Apply gravity to sprite velocities.
2671
+ * 5. Apply velocities to sprite positions.
2672
+ * 6. Call `onUpdate(dt)`.
2673
+ * 7. Advance active trail effects.
2674
+ * 8. Render sprites/effects (with scroll offset).
2675
+ * 9. Render text overlays (screen space, on top of sprites).
2676
+ * 10. Clear per-frame input state.
1075
2677
  *
1076
2678
  * @example
1077
2679
  * ```ts
1078
- * game.onUpdate = (dt) => { ... };
1079
- * game.start();
2680
+ * class DemoScene {
2681
+ * onCreate() {}
2682
+ * onUpdate(dt: number) {}
2683
+ * }
2684
+ *
2685
+ * game.start(new DemoScene());
1080
2686
  * ```
1081
2687
  */
1082
- start(): void;
2688
+ start(scene?: IScene): void;
1083
2689
  /**
1084
2690
  * Stops the game loop. The canvas retains its last rendered frame.
1085
2691
  * Call {@link Game.start} to resume.