melonjs 20.4.0 → 20.5.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 (79) hide show
  1. package/build/audio/backend/sound.d.ts.map +1 -1
  2. package/build/audio/procedural.d.ts +7 -2
  3. package/build/audio/procedural.d.ts.map +1 -1
  4. package/build/audio/types.d.ts +22 -0
  5. package/build/audio/types.d.ts.map +1 -1
  6. package/build/camera/camera2d.d.ts +28 -0
  7. package/build/camera/camera2d.d.ts.map +1 -1
  8. package/build/camera/camera3d.d.ts +24 -3
  9. package/build/camera/camera3d.d.ts.map +1 -1
  10. package/build/geometries/polygon.d.ts +7 -1
  11. package/build/geometries/polygon.d.ts.map +1 -1
  12. package/build/index.d.ts +4 -0
  13. package/build/index.d.ts.map +1 -1
  14. package/build/index.js +1061 -166
  15. package/build/index.js.map +4 -4
  16. package/build/level/gltf/GLTFModel.d.ts +50 -7
  17. package/build/level/gltf/GLTFModel.d.ts.map +1 -1
  18. package/build/lighting/light3d.d.ts +20 -47
  19. package/build/lighting/light3d.d.ts.map +1 -1
  20. package/build/loader/loader.d.ts +106 -6
  21. package/build/loader/loader.d.ts.map +1 -1
  22. package/build/renderable/animation.d.ts +21 -6
  23. package/build/renderable/animation.d.ts.map +1 -1
  24. package/build/renderable/container.d.ts +27 -5
  25. package/build/renderable/container.d.ts.map +1 -1
  26. package/build/renderable/instanced_mesh.d.ts +34 -9
  27. package/build/renderable/instanced_mesh.d.ts.map +1 -1
  28. package/build/renderable/mesh.d.ts +131 -94
  29. package/build/renderable/mesh.d.ts.map +1 -1
  30. package/build/renderable/renderable.d.ts +17 -0
  31. package/build/renderable/renderable.d.ts.map +1 -1
  32. package/build/renderable/sprite3d.d.ts +12 -2
  33. package/build/renderable/sprite3d.d.ts.map +1 -1
  34. package/build/renderable/text/bitmaptext.d.ts +32 -7
  35. package/build/renderable/text/bitmaptext.d.ts.map +1 -1
  36. package/build/renderable/text/text.d.ts +78 -3
  37. package/build/renderable/text/text.d.ts.map +1 -1
  38. package/build/renderable/text/textmetrics.d.ts +2 -0
  39. package/build/renderable/text/textmetrics.d.ts.map +1 -1
  40. package/build/renderable/text/textstyle.d.ts.map +1 -1
  41. package/build/state/stage.d.ts +21 -0
  42. package/build/state/stage.d.ts.map +1 -1
  43. package/build/system/device.d.ts +1 -1
  44. package/build/system/device.d.ts.map +1 -1
  45. package/build/system/save.d.ts +44 -1
  46. package/build/system/save.d.ts.map +1 -1
  47. package/build/video/effects/glsl_realization.d.ts.map +1 -1
  48. package/build/video/effects/mesh_splice.d.ts +2 -0
  49. package/build/video/effects/mesh_splice.d.ts.map +1 -0
  50. package/build/video/effects/shadereffect.d.ts +12 -128
  51. package/build/video/effects/shadereffect.d.ts.map +1 -1
  52. package/build/video/effects/wgsl_realization.d.ts.map +1 -1
  53. package/build/video/gradient.d.ts +19 -0
  54. package/build/video/gradient.d.ts.map +1 -1
  55. package/build/video/renderer.d.ts.map +1 -1
  56. package/build/video/texture/noise_texture2d.d.ts +101 -34
  57. package/build/video/texture/noise_texture2d.d.ts.map +1 -1
  58. package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
  59. package/build/video/webgl/glshader.d.ts +7 -2
  60. package/build/video/webgl/glshader.d.ts.map +1 -1
  61. package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
  62. package/build/video/webgpu/batchers/lit_mesh_batcher.d.ts.map +1 -1
  63. package/build/video/webgpu/batchers/mesh_batcher.d.ts +6 -1
  64. package/build/video/webgpu/batchers/mesh_batcher.d.ts.map +1 -1
  65. package/build/video/webgpu/webgpu_renderer.d.ts +1 -0
  66. package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
  67. package/package.json +1 -1
  68. package/skills/melonjs-3d/SKILL.md +152 -3
  69. package/skills/melonjs-3d-assets/SKILL.md +139 -0
  70. package/skills/melonjs-audio/SKILL.md +17 -0
  71. package/skills/melonjs-camera-and-drawing/SKILL.md +45 -0
  72. package/skills/melonjs-effects-and-shaders/SKILL.md +93 -1
  73. package/skills/melonjs-loading-assets/SKILL.md +97 -1
  74. package/skills/melonjs-performance/SKILL.md +55 -1
  75. package/skills/melonjs-physics/SKILL.md +78 -0
  76. package/skills/melonjs-renderables/SKILL.md +63 -1
  77. package/skills/melonjs-renderer-backends/SKILL.md +19 -0
  78. package/skills/melonjs-scenes-and-state/SKILL.md +56 -0
  79. package/skills/melonjs-ui-and-text/SKILL.md +124 -0
@@ -6,6 +6,96 @@ license: MIT
6
6
 
7
7
  # UI, HUD and text
8
8
 
9
+ ## Outlined text: the stroke eats into the glyph
10
+
11
+ `Text` draws `fillText` and then `strokeText`, so the outline lands **on top of
12
+ the fill** and is centred on the glyph edge — half of it inward. On a small or
13
+ chunky face a `lineWidth` of 3 leaves the letters solid black. Keep it to 1,
14
+ and raise the font size rather than the stroke.
15
+
16
+ The stroke used to cost you the top row of pixels as well, and a display face
17
+ whose glyphs overshoot the nominal ascent did the same on its own: the render
18
+ box was sized from the line height alone, with no allowance for either. **That
19
+ is fixed** — the bake is padded by the ink's real extent and the blit shifts
20
+ back by the same amount, so nothing is clipped and the reported bounds are
21
+ unchanged. Write the string you mean:
22
+
23
+ ```js
24
+ new Text(x, y, { font: "Display", lineWidth: 1, lineHeight: 1.45, text: "" });
25
+ hud.setText("SCORE 100");
26
+ ```
27
+
28
+ If you have a label carrying a leading `\n` to buy headroom, that workaround is
29
+ now dead weight — drop it, and take the line height back off the position you
30
+ shifted it by.
31
+
32
+ ## Gradient text
33
+
34
+ `fillStyle` takes a `Gradient` as well as a colour — the same object
35
+ `Renderer#setColor` accepts, built the way the canvas API builds one:
36
+
37
+ ```js
38
+ const ramp = renderer.createLinearGradient(0, 0, 0, 24); // top to bottom
39
+ ramp.addColorStop(0, "#fffdf0");
40
+ ramp.addColorStop(1, "#f0a020");
41
+
42
+ new Text(x, y, { font: "Display", size: 24, fillStyle: ramp });
43
+ ```
44
+
45
+ Coordinates are the label's own bake: `(0, 0)` is the top-left of the render
46
+ box, so the ramp above runs down one line. A multi-line label **restarts it on
47
+ every line**, reading like one `Text` per line — you do not have to author the
48
+ gradient over the block height. Pass `gradientPerLine: false` for a single ramp
49
+ spanning the whole block, which is what a plain canvas does and what a
50
+ deliberate fade across a two-line title wants.
51
+
52
+ The ramp colours the **fill only** — `Text` strokes in a separate pass, so
53
+ an outline keeps its own colour without any luminance trickery — and it works on
54
+ Canvas2D, which a post effect does not. `fillStyle.alpha` still gates the fill,
55
+ and the property still reads back as a `Color`.
56
+
57
+ ## BitmapText: `size` is a RATIO, not pixels
58
+
59
+ The trap when moving over from `Text`:
60
+
61
+ ```js
62
+ new Text(x, y, { font: "Arial", size: 24, text: "SCORE" }); // 24 pixels
63
+ new BitmapText(x, y, { font: "arial", size: 24, text: "SCORE" }); // 24 TIMES
64
+ ```
65
+
66
+ `size` scales the font's authored size, so `1` is native and `2` is double —
67
+ `resize(scale)` and `set(textAlign, scale)` take the same ratio. Whole numbers
68
+ keep pixel art crisp; fractional ones resample the page image.
69
+
70
+ It has **no stroke** — there is no `strokeStyle` or `lineWidth` here, which is
71
+ part of why it stays sharp. Colour comes from the tint instead:
72
+
73
+ ```js
74
+ const score = new BitmapText(8, 8, {
75
+ font: "arial", text: "1000", fillStyle: "#ffd700",
76
+ });
77
+ score.fillStyle = "#ff4040"; // recolour at any time
78
+ score.fillStyle = new Color(255, 255, 255); // UNTINTED, not "white text"
79
+ ```
80
+
81
+ `fillStyle` is `Renderable#tint` under another name: white is the *absence* of a
82
+ tint and every other colour tints away from it, so author the page in white to
83
+ keep every colour available to you.
84
+
85
+ Load the descriptor as `binary` and its page as `image` under the **same name**.
86
+ Both BMFont flavours — text (`.fnt`) and XML — are auto-detected, so an `.xml`
87
+ descriptor loads as-is:
88
+
89
+ ```js
90
+ loader.preload([
91
+ { name: "arial", type: "binary", src: "data/font/arial.fnt" },
92
+ { name: "arial", type: "image", src: "data/font/arial.png" },
93
+ ]);
94
+ ```
95
+
96
+ Reach for it over `Text` when the text is mostly static, has to stay crisp at
97
+ integer scales, or wants recolouring without a re-bake.
98
+
9
99
  ## The HUD pattern
10
100
 
11
101
  A HUD is a `floating` container at a high z, built once and re-added:
@@ -39,6 +129,40 @@ Three things matter here:
39
129
  real accessor is `depth` (an alias for `pos.z`); `addChild(child, z)` sets it
40
130
  for you.
41
131
 
132
+ ### Buttons: extend the handlers, do not bind listeners
133
+
134
+ `UISpriteElement` is a `Sprite` that already registers itself for pointer
135
+ events, so a button is made by overriding methods rather than by wiring
136
+ `registerPointerEvent`:
137
+
138
+ | handler | fires | returns |
139
+ |---|---|---|
140
+ | `onClick(event)` | pressed | `false` to stop the event propagating |
141
+ | `onRelease(event)` | pressed and released | `false` to stop propagating |
142
+ | `onOver(event)` | pointer enters | — |
143
+ | `onOut(event)` | pointer leaves | — |
144
+ | `onHold()` | pressed and held | — |
145
+
146
+ ```js
147
+ class MuteButton extends UISpriteElement {
148
+ constructor(x, y) {
149
+ super(x, y, { image: atlas, region: "speaker.png" });
150
+ this.setOpacity(0.5);
151
+ }
152
+ onOver() { this.setOpacity(1.0); }
153
+ onOut() { this.setOpacity(0.5); }
154
+ onClick() {
155
+ audio.muteAll();
156
+ return false; // consumed — do not fall through to the world
157
+ }
158
+ }
159
+ ```
160
+
161
+ The pointer still has to reach it: a renderable with `isKinematic = true` — the
162
+ default on a plain `Renderable` — is skipped by the broadphase and receives
163
+ nothing. `UISpriteElement` and `UIBaseElement` clear it for you; anything else
164
+ you make clickable has to clear it itself.
165
+
42
166
  ### In a 3D scene, a HUD needs a SMALL depth
43
167
 
44
168
  `floating` opts a renderable out of the camera transform. It does **not** opt it