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.
- package/README.md +88 -10
- package/build/application/settings.d.ts +4 -2
- package/build/application/settings.d.ts.map +1 -1
- package/build/audio/audio.d.ts +2 -2
- package/build/audio/audio.d.ts.map +1 -1
- package/build/audio/backend/buffer.d.ts +26 -0
- package/build/audio/backend/buffer.d.ts.map +1 -0
- package/build/audio/backend/cache.d.ts +2 -0
- package/build/audio/backend/cache.d.ts.map +1 -0
- package/build/audio/backend/core.d.ts +24 -0
- package/build/audio/backend/core.d.ts.map +1 -0
- package/build/audio/backend/engine.d.ts +54 -0
- package/build/audio/backend/engine.d.ts.map +1 -0
- package/build/audio/backend/sound.d.ts +79 -0
- package/build/audio/backend/sound.d.ts.map +1 -0
- package/build/audio/backend/spatial.d.ts +191 -0
- package/build/audio/backend/spatial.d.ts.map +1 -0
- package/build/audio/backend/types.d.ts +97 -0
- package/build/audio/backend/types.d.ts.map +1 -0
- package/build/audio/backend/voice.d.ts +33 -0
- package/build/audio/backend/voice.d.ts.map +1 -0
- package/build/audio/playback.d.ts +49 -4
- package/build/audio/playback.d.ts.map +1 -1
- package/build/audio/{backend.d.ts → state.d.ts} +13 -11
- package/build/audio/state.d.ts.map +1 -0
- package/build/audio/types.d.ts +93 -1
- package/build/audio/types.d.ts.map +1 -1
- package/build/camera/camera3d.d.ts +5 -5
- package/build/const.d.ts +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +10048 -10341
- package/build/index.js.map +4 -4
- package/build/input/input.d.ts +19 -0
- package/build/input/input.d.ts.map +1 -1
- package/build/input/pointerevent.d.ts.map +1 -1
- package/build/lang/deprecated.d.ts +4 -2
- package/build/lang/deprecated.d.ts.map +1 -1
- package/build/level/gltf/GLTFScene.d.ts +12 -0
- package/build/level/gltf/GLTFScene.d.ts.map +1 -1
- package/build/level/tiled/TMXObjectFactory.d.ts.map +1 -1
- package/build/loader/loader.d.ts +4 -40
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/parsers/audio.d.ts +31 -0
- package/build/loader/parsers/audio.d.ts.map +1 -0
- package/build/loader/parsers/shader.d.ts.map +1 -1
- package/build/particles/emitter.d.ts +81 -3
- package/build/particles/emitter.d.ts.map +1 -1
- package/build/particles/particle.d.ts +62 -1
- package/build/particles/particle.d.ts.map +1 -1
- package/build/particles/settings.d.ts +50 -7
- package/build/particles/settings.d.ts.map +1 -1
- package/build/physics/adapter.d.ts +3 -3
- package/build/physics/builtin/body.d.ts +23 -24
- package/build/physics/builtin/body.d.ts.map +1 -1
- package/build/physics/builtin/detector.d.ts +1 -1
- package/build/plugin/plugin.d.ts +9 -1
- package/build/plugin/plugin.d.ts.map +1 -1
- package/build/polyfill/index.d.ts +1 -4
- package/build/polyfill/index.d.ts.map +1 -1
- package/build/renderable/container.d.ts +10 -0
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/entity/entity.d.ts +10 -0
- package/build/renderable/entity/entity.d.ts.map +1 -1
- package/build/renderable/mesh.d.ts +16 -0
- package/build/renderable/mesh.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +122 -32
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +7 -7
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/state/stage.d.ts +4 -2
- package/build/state/stage.d.ts.map +1 -1
- package/build/system/event.d.ts +1 -1
- package/build/system/platform.d.ts +21 -1
- package/build/system/platform.d.ts.map +1 -1
- package/build/utils/fetchdata.d.ts.map +1 -0
- package/build/video/blendmodes.d.ts +107 -0
- package/build/video/blendmodes.d.ts.map +1 -0
- package/build/video/canvas/canvas_renderer.d.ts +31 -24
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/effects/blendEffect.d.ts +57 -0
- package/build/video/effects/blendEffect.d.ts.map +1 -0
- package/build/video/effects/blur.d.ts +4 -4
- package/build/video/effects/blur.d.ts.map +1 -1
- package/build/video/effects/chromaticAberration.d.ts +5 -5
- package/build/video/effects/chromaticAberration.d.ts.map +1 -1
- package/build/video/effects/colorMatrix.d.ts +5 -5
- package/build/video/effects/colorMatrix.d.ts.map +1 -1
- package/build/video/effects/desaturate.d.ts +5 -5
- package/build/video/effects/desaturate.d.ts.map +1 -1
- package/build/video/effects/dissolve.d.ts +4 -4
- package/build/video/effects/dissolve.d.ts.map +1 -1
- package/build/video/effects/dropShadow.d.ts +5 -5
- package/build/video/effects/dropShadow.d.ts.map +1 -1
- package/build/video/effects/flash.d.ts +4 -4
- package/build/video/effects/flash.d.ts.map +1 -1
- package/build/video/effects/glow.d.ts +5 -5
- package/build/video/effects/glow.d.ts.map +1 -1
- package/build/video/effects/hologram.d.ts +4 -4
- package/build/video/effects/hologram.d.ts.map +1 -1
- package/build/video/effects/invert.d.ts +5 -5
- package/build/video/effects/invert.d.ts.map +1 -1
- package/build/video/effects/outline.d.ts +6 -6
- package/build/video/effects/outline.d.ts.map +1 -1
- package/build/video/effects/pixelate.d.ts +4 -4
- package/build/video/effects/pixelate.d.ts.map +1 -1
- package/build/video/effects/radialGradient.d.ts +2 -2
- package/build/video/effects/scanline.d.ts +6 -6
- package/build/video/effects/scanline.d.ts.map +1 -1
- package/build/video/effects/sepia.d.ts +5 -5
- package/build/video/effects/sepia.d.ts.map +1 -1
- package/build/video/effects/shadereffect.d.ts +12 -10
- package/build/video/effects/shadereffect.d.ts.map +1 -1
- package/build/video/effects/shine.d.ts +3 -3
- package/build/video/effects/shine.d.ts.map +1 -1
- package/build/video/effects/tintPulse.d.ts +4 -4
- package/build/video/effects/tintPulse.d.ts.map +1 -1
- package/build/video/effects/vignette.d.ts +6 -6
- package/build/video/effects/vignette.d.ts.map +1 -1
- package/build/video/effects/wave.d.ts +4 -4
- package/build/video/effects/wave.d.ts.map +1 -1
- package/build/video/renderer.d.ts +3 -4
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/rendertarget/canvasrendertarget.d.ts +1 -0
- package/build/video/rendertarget/canvasrendertarget.d.ts.map +1 -1
- package/build/video/texture/atlas.d.ts +1 -1
- package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
- package/build/video/webgl/glshader.d.ts +2 -2
- package/build/video/webgl/glshader.d.ts.map +1 -1
- package/build/video/webgl/utils/program.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +117 -29
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/build/video/webgpu/batchers/quad_batcher.d.ts +7 -0
- package/build/video/webgpu/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgpu/pipeline/cache.d.ts +0 -9
- package/build/video/webgpu/pipeline/cache.d.ts.map +1 -1
- package/build/video/webgpu/webgpu_renderer.d.ts +101 -6
- package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
- package/package.json +6 -10
- package/skills/AGENTS.md +67 -0
- package/skills/melonjs/SKILL.md +156 -0
- package/skills/melonjs-20-migration/SKILL.md +160 -0
- package/skills/melonjs-3d/SKILL.md +226 -0
- package/skills/melonjs-3d-assets/SKILL.md +239 -0
- package/skills/melonjs-audio/SKILL.md +215 -0
- package/skills/melonjs-camera-and-drawing/SKILL.md +171 -0
- package/skills/melonjs-deployment/SKILL.md +113 -0
- package/skills/melonjs-effects-and-shaders/SKILL.md +177 -0
- package/skills/melonjs-events/SKILL.md +159 -0
- package/skills/melonjs-getting-started/SKILL.md +183 -0
- package/skills/melonjs-input/SKILL.md +166 -0
- package/skills/melonjs-lighting/SKILL.md +139 -0
- package/skills/melonjs-loading-assets/SKILL.md +157 -0
- package/skills/melonjs-particles-and-trails/SKILL.md +136 -0
- package/skills/melonjs-performance/SKILL.md +178 -0
- package/skills/melonjs-physics/SKILL.md +321 -0
- package/skills/melonjs-plugins/SKILL.md +191 -0
- package/skills/melonjs-renderables/SKILL.md +214 -0
- package/skills/melonjs-renderer-backends/SKILL.md +173 -0
- package/skills/melonjs-scenes-and-state/SKILL.md +180 -0
- package/skills/melonjs-sprites-and-animation/SKILL.md +173 -0
- package/skills/melonjs-tilemaps/SKILL.md +193 -0
- package/skills/melonjs-ui-and-text/SKILL.md +175 -0
- package/build/audio/backend.d.ts.map +0 -1
- package/build/loader/parsers/fetchdata.d.ts.map +0 -1
- /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,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAExD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,KAAK;YACH,MAAM,CAAC,MAAM,EAAE,IAAI,GAAG,SAAS,CAAC;oBACtB,MAAM,GAAG,IAAI;mBAChB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;eAC1B,MAAM,EAAE;CACzB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAMxD;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAC1B,YAAY,MAAM,EAClB,aAAa,MAAM,IAAI,EACvB,cAAa,OAAc,KACzB,IAqBF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAmBrD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,IAAI,QAAQ,GAAG,IAAI,CAS/C;AAUD;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEnD;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAKvC;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAO/C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchdata.d.ts","sourceRoot":"","sources":["../../../src/loader/parsers/fetchdata.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,oCALW,MAAM,aACN,MAAM,GACJ,OAAO,CAKnB;AA2DD;;;;;;;;;;;;;;;GAeG;AACH,+BAdW,MAAM,gBACN,MAAM,aACN,MAAM,gBAkDhB"}
|
|
File without changes
|