melonjs 20.1.1 → 20.3.0

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 (165) hide show
  1. package/README.md +88 -10
  2. package/build/application/settings.d.ts +4 -2
  3. package/build/application/settings.d.ts.map +1 -1
  4. package/build/audio/audio.d.ts +2 -2
  5. package/build/audio/audio.d.ts.map +1 -1
  6. package/build/audio/backend/buffer.d.ts +26 -0
  7. package/build/audio/backend/buffer.d.ts.map +1 -0
  8. package/build/audio/backend/cache.d.ts +2 -0
  9. package/build/audio/backend/cache.d.ts.map +1 -0
  10. package/build/audio/backend/core.d.ts +24 -0
  11. package/build/audio/backend/core.d.ts.map +1 -0
  12. package/build/audio/backend/engine.d.ts +54 -0
  13. package/build/audio/backend/engine.d.ts.map +1 -0
  14. package/build/audio/backend/sound.d.ts +79 -0
  15. package/build/audio/backend/sound.d.ts.map +1 -0
  16. package/build/audio/backend/spatial.d.ts +191 -0
  17. package/build/audio/backend/spatial.d.ts.map +1 -0
  18. package/build/audio/backend/types.d.ts +97 -0
  19. package/build/audio/backend/types.d.ts.map +1 -0
  20. package/build/audio/backend/voice.d.ts +33 -0
  21. package/build/audio/backend/voice.d.ts.map +1 -0
  22. package/build/audio/playback.d.ts +49 -4
  23. package/build/audio/playback.d.ts.map +1 -1
  24. package/build/audio/{backend.d.ts → state.d.ts} +13 -11
  25. package/build/audio/state.d.ts.map +1 -0
  26. package/build/audio/types.d.ts +93 -1
  27. package/build/audio/types.d.ts.map +1 -1
  28. package/build/camera/camera3d.d.ts +5 -5
  29. package/build/const.d.ts +2 -2
  30. package/build/index.d.ts.map +1 -1
  31. package/build/index.js +10048 -10341
  32. package/build/index.js.map +4 -4
  33. package/build/input/input.d.ts +19 -0
  34. package/build/input/input.d.ts.map +1 -1
  35. package/build/input/pointerevent.d.ts.map +1 -1
  36. package/build/lang/deprecated.d.ts +4 -2
  37. package/build/lang/deprecated.d.ts.map +1 -1
  38. package/build/level/gltf/GLTFScene.d.ts +12 -0
  39. package/build/level/gltf/GLTFScene.d.ts.map +1 -1
  40. package/build/level/tiled/TMXObjectFactory.d.ts.map +1 -1
  41. package/build/loader/loader.d.ts +4 -40
  42. package/build/loader/loader.d.ts.map +1 -1
  43. package/build/loader/parsers/audio.d.ts +31 -0
  44. package/build/loader/parsers/audio.d.ts.map +1 -0
  45. package/build/loader/parsers/shader.d.ts.map +1 -1
  46. package/build/particles/emitter.d.ts +81 -3
  47. package/build/particles/emitter.d.ts.map +1 -1
  48. package/build/particles/particle.d.ts +62 -1
  49. package/build/particles/particle.d.ts.map +1 -1
  50. package/build/particles/settings.d.ts +50 -7
  51. package/build/particles/settings.d.ts.map +1 -1
  52. package/build/physics/adapter.d.ts +3 -3
  53. package/build/physics/builtin/body.d.ts +23 -24
  54. package/build/physics/builtin/body.d.ts.map +1 -1
  55. package/build/physics/builtin/detector.d.ts +1 -1
  56. package/build/plugin/plugin.d.ts +9 -1
  57. package/build/plugin/plugin.d.ts.map +1 -1
  58. package/build/polyfill/index.d.ts +1 -4
  59. package/build/polyfill/index.d.ts.map +1 -1
  60. package/build/renderable/container.d.ts +10 -0
  61. package/build/renderable/container.d.ts.map +1 -1
  62. package/build/renderable/entity/entity.d.ts +10 -0
  63. package/build/renderable/entity/entity.d.ts.map +1 -1
  64. package/build/renderable/mesh.d.ts +16 -0
  65. package/build/renderable/mesh.d.ts.map +1 -1
  66. package/build/renderable/renderable.d.ts +122 -32
  67. package/build/renderable/renderable.d.ts.map +1 -1
  68. package/build/renderable/sprite.d.ts +7 -7
  69. package/build/renderable/sprite.d.ts.map +1 -1
  70. package/build/state/stage.d.ts +4 -2
  71. package/build/state/stage.d.ts.map +1 -1
  72. package/build/system/event.d.ts +1 -1
  73. package/build/system/platform.d.ts +21 -1
  74. package/build/system/platform.d.ts.map +1 -1
  75. package/build/utils/fetchdata.d.ts.map +1 -0
  76. package/build/video/blendmodes.d.ts +107 -0
  77. package/build/video/blendmodes.d.ts.map +1 -0
  78. package/build/video/canvas/canvas_renderer.d.ts +31 -24
  79. package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
  80. package/build/video/effects/blendEffect.d.ts +57 -0
  81. package/build/video/effects/blendEffect.d.ts.map +1 -0
  82. package/build/video/effects/blur.d.ts +4 -4
  83. package/build/video/effects/blur.d.ts.map +1 -1
  84. package/build/video/effects/chromaticAberration.d.ts +5 -5
  85. package/build/video/effects/chromaticAberration.d.ts.map +1 -1
  86. package/build/video/effects/colorMatrix.d.ts +5 -5
  87. package/build/video/effects/colorMatrix.d.ts.map +1 -1
  88. package/build/video/effects/desaturate.d.ts +5 -5
  89. package/build/video/effects/desaturate.d.ts.map +1 -1
  90. package/build/video/effects/dissolve.d.ts +4 -4
  91. package/build/video/effects/dissolve.d.ts.map +1 -1
  92. package/build/video/effects/dropShadow.d.ts +5 -5
  93. package/build/video/effects/dropShadow.d.ts.map +1 -1
  94. package/build/video/effects/flash.d.ts +4 -4
  95. package/build/video/effects/flash.d.ts.map +1 -1
  96. package/build/video/effects/glow.d.ts +5 -5
  97. package/build/video/effects/glow.d.ts.map +1 -1
  98. package/build/video/effects/hologram.d.ts +4 -4
  99. package/build/video/effects/hologram.d.ts.map +1 -1
  100. package/build/video/effects/invert.d.ts +5 -5
  101. package/build/video/effects/invert.d.ts.map +1 -1
  102. package/build/video/effects/outline.d.ts +6 -6
  103. package/build/video/effects/outline.d.ts.map +1 -1
  104. package/build/video/effects/pixelate.d.ts +4 -4
  105. package/build/video/effects/pixelate.d.ts.map +1 -1
  106. package/build/video/effects/radialGradient.d.ts +2 -2
  107. package/build/video/effects/scanline.d.ts +6 -6
  108. package/build/video/effects/scanline.d.ts.map +1 -1
  109. package/build/video/effects/sepia.d.ts +5 -5
  110. package/build/video/effects/sepia.d.ts.map +1 -1
  111. package/build/video/effects/shadereffect.d.ts +12 -10
  112. package/build/video/effects/shadereffect.d.ts.map +1 -1
  113. package/build/video/effects/shine.d.ts +3 -3
  114. package/build/video/effects/shine.d.ts.map +1 -1
  115. package/build/video/effects/tintPulse.d.ts +4 -4
  116. package/build/video/effects/tintPulse.d.ts.map +1 -1
  117. package/build/video/effects/vignette.d.ts +6 -6
  118. package/build/video/effects/vignette.d.ts.map +1 -1
  119. package/build/video/effects/wave.d.ts +4 -4
  120. package/build/video/effects/wave.d.ts.map +1 -1
  121. package/build/video/renderer.d.ts +3 -4
  122. package/build/video/renderer.d.ts.map +1 -1
  123. package/build/video/rendertarget/canvasrendertarget.d.ts +1 -0
  124. package/build/video/rendertarget/canvasrendertarget.d.ts.map +1 -1
  125. package/build/video/texture/atlas.d.ts +1 -1
  126. package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
  127. package/build/video/webgl/glshader.d.ts +2 -2
  128. package/build/video/webgl/glshader.d.ts.map +1 -1
  129. package/build/video/webgl/utils/program.d.ts.map +1 -1
  130. package/build/video/webgl/webgl_renderer.d.ts +117 -29
  131. package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
  132. package/build/video/webgpu/batchers/quad_batcher.d.ts +7 -0
  133. package/build/video/webgpu/batchers/quad_batcher.d.ts.map +1 -1
  134. package/build/video/webgpu/pipeline/cache.d.ts +0 -9
  135. package/build/video/webgpu/pipeline/cache.d.ts.map +1 -1
  136. package/build/video/webgpu/webgpu_renderer.d.ts +101 -6
  137. package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
  138. package/package.json +6 -10
  139. package/skills/AGENTS.md +67 -0
  140. package/skills/melonjs/SKILL.md +156 -0
  141. package/skills/melonjs-20-migration/SKILL.md +160 -0
  142. package/skills/melonjs-3d/SKILL.md +226 -0
  143. package/skills/melonjs-3d-assets/SKILL.md +239 -0
  144. package/skills/melonjs-audio/SKILL.md +215 -0
  145. package/skills/melonjs-camera-and-drawing/SKILL.md +171 -0
  146. package/skills/melonjs-deployment/SKILL.md +113 -0
  147. package/skills/melonjs-effects-and-shaders/SKILL.md +177 -0
  148. package/skills/melonjs-events/SKILL.md +159 -0
  149. package/skills/melonjs-getting-started/SKILL.md +183 -0
  150. package/skills/melonjs-input/SKILL.md +166 -0
  151. package/skills/melonjs-lighting/SKILL.md +139 -0
  152. package/skills/melonjs-loading-assets/SKILL.md +157 -0
  153. package/skills/melonjs-particles-and-trails/SKILL.md +136 -0
  154. package/skills/melonjs-performance/SKILL.md +178 -0
  155. package/skills/melonjs-physics/SKILL.md +321 -0
  156. package/skills/melonjs-plugins/SKILL.md +191 -0
  157. package/skills/melonjs-renderables/SKILL.md +214 -0
  158. package/skills/melonjs-renderer-backends/SKILL.md +173 -0
  159. package/skills/melonjs-scenes-and-state/SKILL.md +180 -0
  160. package/skills/melonjs-sprites-and-animation/SKILL.md +173 -0
  161. package/skills/melonjs-tilemaps/SKILL.md +193 -0
  162. package/skills/melonjs-ui-and-text/SKILL.md +175 -0
  163. package/build/audio/backend.d.ts.map +0 -1
  164. package/build/loader/parsers/fetchdata.d.ts.map +0 -1
  165. /package/build/{loader/parsers → utils}/fetchdata.d.ts +0 -0
@@ -0,0 +1,175 @@
1
+ ---
2
+ name: melonjs-ui-and-text
3
+ description: "Use this skill for HUDs, buttons, menus, dialogue panels and on-screen text in melonJS. Covers UIBaseElement/UISpriteElement/UITextButton, Draggable and DropTarget, the floating screen-space container pattern, Text and BitmapText, web font loading, and NineSliceSprite panels. Triggers on: UI, HUD, button, UIBaseElement, UISpriteElement, UITextButton, Draggable, DropTarget, menu, dialogue, Text, BitmapText, font, fontface, wordWrapWidth, NineSliceSprite, score display, floating."
4
+ license: MIT
5
+ ---
6
+
7
+ # UI, HUD and text
8
+
9
+ ## The HUD pattern
10
+
11
+ A HUD is a `floating` container at a high z, built once and re-added:
12
+
13
+ ```js
14
+ class HUD extends Container {
15
+ constructor(app) {
16
+ super(0, 0, app.viewport.width, app.viewport.height);
17
+ this.floating = true; // screen space, not world space
18
+ this.isPersistent = true; // survives a world reset
19
+ }
20
+ }
21
+
22
+ app.world.addChild(new HUD(app), 100); // explicit z — not `.z = Infinity`
23
+ ```
24
+
25
+ There is no `UIContainer` class. Use `Container`, or `UIBaseElement` when the
26
+ panel itself must react to the pointer — it is a `Container` that already sets
27
+ `floating = true` and `isKinematic = false`.
28
+
29
+ Three things matter here:
30
+
31
+ - **`floating = true`** opts the container out of camera transforms, so it stays
32
+ put while the world scrolls. Without it the HUD scrolls away — a silent
33
+ failure.
34
+ - **Only the parent container needs `floating`.** `addChild` forces
35
+ `child.floating = false` under a floating parent, and the container applies one
36
+ projection swap for the whole subtree.
37
+ - **Pass an explicit z.** `this.z = Number.POSITIVE_INFINITY` appears in several
38
+ shipped examples and does nothing — `renderable.z` is not a real property. The
39
+ real accessor is `depth` (an alias for `pos.z`); `addChild(child, z)` sets it
40
+ for you.
41
+
42
+ Relayout on resize by listening for `event.CANVAS_ONRESIZE`.
43
+
44
+ ## Buttons and interactive elements
45
+
46
+ Use the built-ins rather than hand-rolling — they set `isKinematic = false` for
47
+ you, which is the trap that stops hand-rolled buttons receiving clicks at all.
48
+
49
+ ```js
50
+ class PlayButton extends UISpriteElement {
51
+ constructor(x, y) {
52
+ super(x, y, { image: atlas, region: "play.png" });
53
+ }
54
+ onClick() { state.change(state.PLAY); return false; }
55
+ onOver() { this.setOpacity(1.0); }
56
+ onOut() { this.setOpacity(0.8); }
57
+ onRelease() { return false; }
58
+ }
59
+ ```
60
+
61
+ | class | for |
62
+ |---|---|
63
+ | `UIBaseElement` | a `Container` base — clickable, optionally draggable and holdable |
64
+ | `UISpriteElement` | a `Sprite`-backed button with hover/press callbacks |
65
+ | `UITextButton` | a `BitmapText` label on a `RoundRect` background — it needs a **bitmap** font, not a `fontface` |
66
+ | `Draggable` / `DropTarget` | drag-and-drop; `dropTarget.setCheckMethod(dropTarget.CHECKMETHOD_CONTAINS)` to require containment instead of overlap |
67
+
68
+ The callbacks to override are `onClick`, `onOver`, `onOut`, `onRelease` and
69
+ `onHold`; `UIBaseElement` adds `onMove` while dragging. Returning `false` from
70
+ `onClick` / `onRelease` stops the event propagating further.
71
+
72
+ ## Text
73
+
74
+ ```js
75
+ new Text(x, y, {
76
+ font: "Arial",
77
+ size: 32,
78
+ fillStyle: "#FFFFFF",
79
+ textAlign: "center",
80
+ textBaseline: "middle",
81
+ text: "Score: 0",
82
+ wordWrapWidth: 400, // enables wrapping
83
+ });
84
+ ```
85
+
86
+ `text` accepts a string or an array of lines. Update with `setText()`.
87
+
88
+ **Custom web fonts must be preloaded** with the `"fontface"` asset type:
89
+
90
+ ```js
91
+ { name: "PressStart2P", type: "fontface", src: "data/font/PressStart2P.ttf" }
92
+ ```
93
+
94
+ Drawing before the font has loaded silently renders in a fallback font — the
95
+ layout looks subtly wrong rather than failing.
96
+
97
+ ## `BitmapText`
98
+
99
+ For pixel-perfect text that scales without antialiasing, and for text drawn in
100
+ volume: every `BitmapText` sharing a font draws glyph quads from that one page
101
+ image, so they batch together. Each `Text` instead owns a private canvas
102
+ texture (re-rasterised whenever it changes), so a screenful of them is a
103
+ screenful of distinct textures.
104
+
105
+ ```js
106
+ await loader.preload([
107
+ { name: "PressStart2P", type: "image", src: "data/font/font.png" },
108
+ { name: "PressStart2P", type: "binary", src: "data/font/font.fnt" },
109
+ ]);
110
+
111
+ new BitmapText(x, y, {
112
+ font: "PressStart2P",
113
+ size: 2, // a scale ratio, not a pixel size
114
+ text: "GAME OVER",
115
+ });
116
+ ```
117
+
118
+ It needs **both** assets, and by default they must share the **same asset
119
+ name** — `settings.font` resolves the image *and*, unless you pass
120
+ `settings.fontData`, the descriptor. Registering the descriptor under a
121
+ different name (`"…-fnt"`) is the usual mistake; either use one name for both,
122
+ or pass `fontData: "PressStart2P-fnt"` explicitly.
123
+
124
+ The descriptor is AngelCode BMFont in either flavour — the text `.fnt` form or
125
+ the XML form — auto-detected, so an `.xml` export loads as-is.
126
+
127
+ ## Never draw text through the raw context
128
+
129
+ ```js
130
+ // ✗ works on Canvas only — getContext() returns the GL/GPU context on the
131
+ // GPU backends, and neither has fillText
132
+ app.renderer.getContext().fillText("hi", 10, 10);
133
+
134
+ // ✓
135
+ world.addChild(new Text(10, 10, { text: "hi", /* … */ }));
136
+ ```
137
+
138
+ `getContext()` hands back the *backend's* context — a
139
+ `CanvasRenderingContext2D` only under the Canvas renderer. On WebGL or WebGPU
140
+ the call throws `TypeError: … .fillText is not a function`, so this fails loudly
141
+ — but only on the machines that picked a GPU backend, which under `video.AUTO`
142
+ is most of them and probably not yours.
143
+
144
+ ## Panels
145
+
146
+ `NineSliceSprite` stretches a panel without distorting its corners — the right
147
+ tool for dialogue boxes and windows:
148
+
149
+ ```js
150
+ new NineSliceSprite(x, y, {
151
+ image: "panel", width: 300, height: 120, insetx: 12, insety: 12,
152
+ });
153
+ ```
154
+
155
+ The inset keys are lowercase `insetx` / `insety`; `insetX` is silently ignored
156
+ and the corners fall back to a quarter of the frame. `width` and `height` are
157
+ mandatory — the constructor throws without them.
158
+
159
+ ## Symptom → cause
160
+
161
+ | symptom | cause |
162
+ |---|---|
163
+ | HUD scrolls away with the camera | missing `floating = true` on the container |
164
+ | HUD drawn under the game | `this.z = …` instead of `addChild(hud, z)` |
165
+ | hand-rolled button never responds | `isKinematic` left `true` — use `UISpriteElement` |
166
+ | text renders in the wrong font | web font not preloaded as `"fontface"` |
167
+ | `BitmapText` renders nothing | the `.fnt` / image pair was loaded under two different asset names |
168
+ | `TypeError: … .fillText is not a function` | drawn via `getContext()` under a GPU backend |
169
+ | `UIContainer is not defined` | no such class — use `Container` or `UIBaseElement` |
170
+ | UI misplaced after a window resize | no `CANVAS_ONRESIZE` relayout |
171
+
172
+ ## Related skills
173
+
174
+ - `melonjs-input` — the `isKinematic` requirement in full
175
+ - `melonjs-renderables` — `floating`, draw order, containers
@@ -1 +0,0 @@
1
- {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/audio/backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,IAAI,EAAU,MAAM,QAAQ,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,eAAO,IAAI,gBAAgB,EAAE,OAAc,CAA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,aACN,MAAM,GACJ,OAAO,CAKnB;AA2DD;;;;;;;;;;;;;;;GAeG;AACH,+BAdW,MAAM,gBACN,MAAM,aACN,MAAM,gBAkDhB"}
File without changes