melonjs 20.7.0 → 20.8.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 +6 -3
- package/build/application/defaultApplicationSettings.d.ts +5 -0
- package/build/application/defaultApplicationSettings.d.ts.map +1 -1
- package/build/application/header.d.ts.map +1 -1
- package/build/application/settings.d.ts +88 -0
- package/build/application/settings.d.ts.map +1 -1
- package/build/audio/backend/engine.d.ts +0 -1
- package/build/audio/backend/sound.d.ts +0 -1
- package/build/camera/camera2d.d.ts.map +1 -1
- package/build/camera/camera3d.d.ts +95 -8
- package/build/camera/camera3d.d.ts.map +1 -1
- package/build/geometries/box3d.d.ts +24 -6
- package/build/geometries/box3d.d.ts.map +1 -1
- package/build/geometries/ellipse.d.ts +14 -0
- package/build/geometries/ellipse.d.ts.map +1 -1
- package/build/geometries/polygon.d.ts +14 -0
- package/build/geometries/polygon.d.ts.map +1 -1
- package/build/geometries/sphere.d.ts +35 -6
- package/build/geometries/sphere.d.ts.map +1 -1
- package/build/index.d.ts +9 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2770 -538
- package/build/index.js.map +4 -4
- package/build/input/pointerevent.d.ts +8 -0
- package/build/input/pointerevent.d.ts.map +1 -1
- package/build/level/gltf/GLTFModel.d.ts +17 -31
- package/build/level/gltf/GLTFModel.d.ts.map +1 -1
- package/build/level/gltf/GLTFScene.d.ts +40 -1
- package/build/level/gltf/GLTFScene.d.ts.map +1 -1
- package/build/level/level.d.ts +35 -0
- package/build/level/level.d.ts.map +1 -1
- package/build/level/tiled/TMXLayer.d.ts +5 -2
- package/build/level/tiled/TMXLayer.d.ts.map +1 -1
- package/build/level/tiled/TMXObject.d.ts +0 -1
- package/build/level/tiled/TMXTile.d.ts +2 -1
- package/build/level/tiled/TMXTile.d.ts.map +1 -1
- package/build/level/tiled/TMXTileMap.d.ts +7 -4
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/level/tiled/TMXTileset.d.ts +1 -1
- package/build/level/tiled/TMXTileset.d.ts.map +1 -1
- package/build/level/tiled/TMXTilesetGroup.d.ts +5 -0
- package/build/level/tiled/TMXTilesetGroup.d.ts.map +1 -1
- package/build/level/tiled/factories/shape.d.ts +0 -1
- package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts +6 -5
- package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts +5 -0
- package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts +8 -7
- package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts +5 -0
- package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXRenderer.d.ts +19 -4
- package/build/level/tiled/renderer/TMXRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/autodetect.d.ts +0 -4
- package/build/level/tiled/renderer/autodetect.d.ts.map +1 -1
- package/build/loader/loader.d.ts +9 -0
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/loadingscreen.d.ts +1 -2
- package/build/loader/loadingscreen.d.ts.map +1 -1
- package/build/loader/parsers/shader.d.ts +0 -2
- package/build/math/color.d.ts +27 -4
- package/build/math/color.d.ts.map +1 -1
- package/build/particles/emitter.d.ts.map +1 -1
- package/build/particles/particle.d.ts +22 -1
- package/build/particles/particle.d.ts.map +1 -1
- package/build/particles/settings.d.ts +69 -0
- package/build/particles/settings.d.ts.map +1 -1
- package/build/physics/adapter.d.ts +9 -1
- package/build/physics/adapter.d.ts.map +1 -1
- package/build/physics/builtin/body.d.ts +3 -2
- package/build/physics/builtin/body.d.ts.map +1 -1
- package/build/physics/builtin/builtin-adapter.d.ts.map +1 -1
- package/build/physics/builtin/detector.d.ts +0 -1
- package/build/physics/builtin/detector.d.ts.map +1 -1
- package/build/physics/builtin/sat.d.ts +0 -7
- package/build/physics/builtin/sat3d.d.ts +46 -0
- package/build/physics/builtin/sat3d.d.ts.map +1 -1
- package/build/physics/response.d.ts +45 -62
- package/build/physics/response.d.ts.map +1 -1
- package/build/renderable/collectable.d.ts +6 -1
- package/build/renderable/collectable.d.ts.map +1 -1
- package/build/renderable/colorlayer.d.ts +4 -4
- package/build/renderable/colorlayer.d.ts.map +1 -1
- package/build/renderable/container.d.ts +23 -17
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/entity/entity.d.ts +12 -16
- package/build/renderable/entity/entity.d.ts.map +1 -1
- package/build/renderable/frameAnimation.d.ts +1 -1
- package/build/renderable/groundshadow.d.ts +1 -0
- package/build/renderable/groundshadow.d.ts.map +1 -1
- package/build/renderable/imagelayer.d.ts +12 -5
- package/build/renderable/imagelayer.d.ts.map +1 -1
- package/build/renderable/instanced_mesh.d.ts +2 -9
- package/build/renderable/instanced_mesh.d.ts.map +1 -1
- package/build/renderable/mesh.d.ts +283 -4
- package/build/renderable/mesh.d.ts.map +1 -1
- package/build/renderable/nineslicesprite.d.ts +3 -13
- package/build/renderable/nineslicesprite.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +90 -27
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +5 -19
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/sprite3d.d.ts +27 -16
- package/build/renderable/sprite3d.d.ts.map +1 -1
- package/build/renderable/text/bitmaptext.d.ts +13 -3
- package/build/renderable/text/bitmaptext.d.ts.map +1 -1
- package/build/renderable/text/bitmaptextdata.d.ts +0 -4
- package/build/renderable/text/bitmaptextdata.d.ts.map +1 -1
- package/build/renderable/text/text.d.ts +5 -3
- package/build/renderable/text/text.d.ts.map +1 -1
- package/build/renderable/text/textmetrics.d.ts +2 -0
- package/build/renderable/text/textmetrics.d.ts.map +1 -1
- package/build/renderable/trail.d.ts +0 -1
- package/build/renderable/trail.d.ts.map +1 -1
- package/build/renderable/trigger.d.ts +27 -5
- package/build/renderable/trigger.d.ts.map +1 -1
- package/build/renderable/ui/progressbar.d.ts +194 -0
- package/build/renderable/ui/progressbar.d.ts.map +1 -0
- package/build/renderable/ui/uibaseelement.d.ts +48 -3
- package/build/renderable/ui/uibaseelement.d.ts.map +1 -1
- package/build/renderable/ui/uispriteelement.d.ts +19 -3
- package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
- package/build/system/legacy_pool.d.ts +2 -2
- package/build/system/legacy_pool.d.ts.map +1 -1
- package/build/system/pool.d.ts +10 -0
- package/build/system/pool.d.ts.map +1 -1
- package/build/tweens/tween.d.ts +49 -2
- package/build/tweens/tween.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +34 -23
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/effects/blendEffect.d.ts +0 -1
- package/build/video/effects/bloom.d.ts +72 -0
- package/build/video/effects/bloom.d.ts.map +1 -0
- package/build/video/effects/blur.d.ts +3 -2
- package/build/video/effects/blur.d.ts.map +1 -1
- package/build/video/effects/chromaticAberration.d.ts +3 -2
- package/build/video/effects/chromaticAberration.d.ts.map +1 -1
- package/build/video/effects/colorMatrix.d.ts +3 -2
- package/build/video/effects/colorMatrix.d.ts.map +1 -1
- package/build/video/effects/desaturate.d.ts +10 -2
- package/build/video/effects/desaturate.d.ts.map +1 -1
- package/build/video/effects/dissolve.d.ts +3 -2
- package/build/video/effects/dissolve.d.ts.map +1 -1
- package/build/video/effects/dropShadow.d.ts +3 -2
- package/build/video/effects/dropShadow.d.ts.map +1 -1
- package/build/video/effects/flash.d.ts +3 -2
- package/build/video/effects/flash.d.ts.map +1 -1
- package/build/video/effects/glow.d.ts +3 -2
- package/build/video/effects/glow.d.ts.map +1 -1
- package/build/video/effects/hologram.d.ts +3 -2
- package/build/video/effects/hologram.d.ts.map +1 -1
- package/build/video/effects/invert.d.ts +10 -2
- package/build/video/effects/invert.d.ts.map +1 -1
- package/build/video/effects/outline.d.ts +3 -2
- package/build/video/effects/outline.d.ts.map +1 -1
- package/build/video/effects/pixelate.d.ts +3 -2
- package/build/video/effects/pixelate.d.ts.map +1 -1
- package/build/video/effects/radialGradient.d.ts +8 -3
- package/build/video/effects/radialGradient.d.ts.map +1 -1
- package/build/video/effects/scanline.d.ts +3 -2
- package/build/video/effects/scanline.d.ts.map +1 -1
- package/build/video/effects/sepia.d.ts +10 -2
- package/build/video/effects/sepia.d.ts.map +1 -1
- package/build/video/effects/shadereffect.d.ts +10 -4
- package/build/video/effects/shadereffect.d.ts.map +1 -1
- package/build/video/effects/shine.d.ts +3 -2
- package/build/video/effects/shine.d.ts.map +1 -1
- package/build/video/effects/tintPulse.d.ts +3 -2
- package/build/video/effects/tintPulse.d.ts.map +1 -1
- package/build/video/effects/tonemap.d.ts +121 -0
- package/build/video/effects/tonemap.d.ts.map +1 -0
- package/build/video/effects/vignette.d.ts +3 -2
- package/build/video/effects/vignette.d.ts.map +1 -1
- package/build/video/effects/wave.d.ts +3 -2
- package/build/video/effects/wave.d.ts.map +1 -1
- package/build/video/gpu/vertexformat.d.ts +26 -0
- package/build/video/gpu/vertexformat.d.ts.map +1 -1
- package/build/video/gradient.d.ts +0 -1
- package/build/video/gradient.d.ts.map +1 -1
- package/build/video/renderer.d.ts +111 -7
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/renderstate.d.ts +2 -0
- package/build/video/renderstate.d.ts.map +1 -1
- package/build/video/rendertarget/canvasrendertarget.d.ts +3 -4
- package/build/video/rendertarget/canvasrendertarget.d.ts.map +1 -1
- package/build/video/rendertarget/render_target_pool.d.ts +0 -1
- package/build/video/rendertarget/webglrendertarget.d.ts +0 -1
- package/build/video/rendertarget/webglrendertarget.d.ts.map +1 -1
- package/build/video/rendertarget/webgpurendertarget.d.ts +18 -2
- package/build/video/rendertarget/webgpurendertarget.d.ts.map +1 -1
- package/build/video/texture/atlas.d.ts +1 -0
- package/build/video/texture/atlas.d.ts.map +1 -1
- package/build/video/texture/cache.d.ts +1 -3
- package/build/video/texture/frametexture.d.ts +0 -1
- package/build/video/texture/frametexture.d.ts.map +1 -1
- package/build/video/texture/noise_texture2d.d.ts +1 -0
- package/build/video/texture/noise_texture2d.d.ts.map +1 -1
- package/build/video/utils/autodetect.d.ts +0 -2
- package/build/video/webgl/batchers/batcher.d.ts +0 -9
- package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts +11 -0
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/material_batcher.d.ts +4 -2
- package/build/video/webgl/batchers/material_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/mesh_batcher.d.ts +0 -3
- package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/quad_batcher.d.ts +4 -0
- package/build/video/webgl/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/buffer/index.d.ts +0 -1
- package/build/video/webgl/buffer/retained_geometry.d.ts +0 -1
- package/build/video/webgl/glshader.d.ts +5 -3
- package/build/video/webgl/glshader.d.ts.map +1 -1
- package/build/video/webgl/renderers/tmxlayer/orthogonal.d.ts +0 -4
- package/build/video/webgl/texture/store.d.ts +0 -1
- package/build/video/webgl/webgl_renderer.d.ts +63 -24
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/build/video/webgpu/batchers/mesh_batcher.d.ts +0 -3
- package/build/video/webgpu/batchers/mesh_batcher.d.ts.map +1 -1
- package/build/video/webgpu/batchers/quad_batcher.d.ts +0 -2
- package/build/video/webgpu/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgpu/batchers/webgpu_batcher.d.ts +0 -2
- package/build/video/webgpu/batchers/webgpu_batcher.d.ts.map +1 -1
- package/build/video/webgpu/pipeline/cache.d.ts.map +1 -1
- package/build/video/webgpu/renderers/tmxlayer/orthogonal.d.ts +0 -2
- package/build/video/webgpu/texture/frametexture.d.ts +0 -2
- package/build/video/webgpu/texture/frametexture.d.ts.map +1 -1
- package/build/video/webgpu/texture/store.d.ts +0 -1
- package/build/video/webgpu/webgpu_renderer.d.ts +7 -75
- package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/melonjs-3d/SKILL.md +277 -19
- package/skills/melonjs-3d-assets/SKILL.md +76 -9
- package/skills/melonjs-camera-and-drawing/SKILL.md +57 -1
- package/skills/melonjs-effects-and-shaders/SKILL.md +341 -29
- package/skills/melonjs-input/SKILL.md +48 -4
- package/skills/melonjs-particles-and-trails/SKILL.md +106 -4
- package/skills/melonjs-performance/SKILL.md +79 -2
- package/skills/melonjs-physics/SKILL.md +101 -27
- package/skills/melonjs-renderables/SKILL.md +2 -1
- package/skills/melonjs-scenes-and-state/SKILL.md +121 -1
- package/skills/melonjs-ui-and-text/SKILL.md +165 -4
- package/build/level/gltf/srgb.d.ts +0 -20
- package/build/level/gltf/srgb.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
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."
|
|
3
|
+
description: "Use this skill for HUDs, buttons, menus, dialogue panels, progress bars and on-screen text in melonJS. Covers UIBaseElement/UISpriteElement/UITextButton, ProgressBar, Draggable and DropTarget, the floating screen-space container pattern, which of two overlapping panels gets the pointer, Text and BitmapText, web font loading, and NineSliceSprite panels. Triggers on: UI, HUD, button, UIBaseElement, UISpriteElement, UITextButton, ProgressBar, progress bar, health bar, gauge, Draggable, DropTarget, menu, dialogue, overlapping panels, moveToTop, onOver, onClick, Tween, easing, animate a label, Text, BitmapText, fillStyle, fillGradient, gradient text, tint, font, fontface, wordWrapWidth, NineSliceSprite, score display, floating."
|
|
4
4
|
license: MIT
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -51,8 +51,24 @@ deliberate fade across a two-line title wants.
|
|
|
51
51
|
|
|
52
52
|
The ramp colours the **fill only** — `Text` strokes in a separate pass, so
|
|
53
53
|
an outline keeps its own colour without any luminance trickery — and it works on
|
|
54
|
-
Canvas2D, which a post effect does not.
|
|
55
|
-
|
|
54
|
+
Canvas2D, which a post effect does not.
|
|
55
|
+
|
|
56
|
+
### The gradient does not live in `fillStyle`
|
|
57
|
+
|
|
58
|
+
`fillStyle` ACCEPTS a `Gradient`; it never HOLDS one. The constructor routes it
|
|
59
|
+
to `fillGradient` and leaves `fillStyle` as the pooled `Color` it always is,
|
|
60
|
+
which is what keeps `fillStyle.alpha` gating the fill and keeps the colour
|
|
61
|
+
owned by the pool.
|
|
62
|
+
|
|
63
|
+
So changing the ramp later means assigning the field it actually landed in:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
label.fillGradient = ramp; // ✓
|
|
67
|
+
label.fillStyle = ramp; // ✗ TS2740: Gradient is not a Color
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The ramp is authored for ONE line height, so a label that changes size needs a
|
|
71
|
+
new one built at the new size; there is nothing that rescales it for you.
|
|
56
72
|
|
|
57
73
|
## BitmapText: `size` is a RATIO, not pixels
|
|
58
74
|
|
|
@@ -96,6 +112,19 @@ loader.preload([
|
|
|
96
112
|
Reach for it over `Text` when the text is mostly static, has to stay crisp at
|
|
97
113
|
integer scales, or wants recolouring without a re-bake.
|
|
98
114
|
|
|
115
|
+
### `fillStyle` means two different things
|
|
116
|
+
|
|
117
|
+
The name is shared and the behaviour is not, which is the trap when moving a
|
|
118
|
+
label from one class to the other:
|
|
119
|
+
|
|
120
|
+
| | `Text` | `BitmapText` |
|
|
121
|
+
|---|---|---|
|
|
122
|
+
| what `fillStyle` holds | a real `Color`, the fill | `Renderable#tint`, under another name |
|
|
123
|
+
| white | white glyphs | the ABSENCE of a tint |
|
|
124
|
+
| gradient | yes, via `fillGradient` | no: a tint is one colour over a page image |
|
|
125
|
+
| stroke | `strokeStyle` + `lineWidth` | none |
|
|
126
|
+
| `size` | pixels | a RATIO of the authored size |
|
|
127
|
+
|
|
99
128
|
## The HUD pattern
|
|
100
129
|
|
|
101
130
|
A HUD is a `floating` container at a high z, built once and re-added:
|
|
@@ -129,6 +158,79 @@ Three things matter here:
|
|
|
129
158
|
real accessor is `depth` (an alias for `pos.z`); `addChild(child, z)` sets it
|
|
130
159
|
for you.
|
|
131
160
|
|
|
161
|
+
### Bars and gauges: `ProgressBar`
|
|
162
|
+
|
|
163
|
+
A health bar, a shield gauge, a cooldown and a loading bar are one object. Set
|
|
164
|
+
`value`; it redraws.
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
const hp = new ProgressBar(20, 20, {
|
|
168
|
+
width: 200, height: 24,
|
|
169
|
+
min: 0, max: 100, value: 100, // min/max default to 0 and 1
|
|
170
|
+
trackColor: "#0000001a",
|
|
171
|
+
fillColor: "#c0392b",
|
|
172
|
+
borderColor: "black", borderWidth: 2,
|
|
173
|
+
padding: 2, // inset of the fill inside the track
|
|
174
|
+
radius: 6, // 0 is square
|
|
175
|
+
});
|
|
176
|
+
hud.addChild(hp);
|
|
177
|
+
|
|
178
|
+
hp.value -= 15; // clamps; `ratio` reads back 0..1
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`direction` takes `"left-to-right"` (the default), `"right-to-left"`,
|
|
182
|
+
`"top-to-bottom"` or `"bottom-to-top"`, each growing from its own edge.
|
|
183
|
+
|
|
184
|
+
**The colour follows the value by mutating the `Color` you passed.** This is
|
|
185
|
+
the one non-obvious part, and it is deliberate: every game wants a different
|
|
186
|
+
rule, and most want the colour somewhere else too, next to a shader uniform or
|
|
187
|
+
a glow. The bar re-reads `fillColor` every frame, so it never has to know:
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
const full = new Color().parseCSS("#7fe0ff");
|
|
191
|
+
const empty = new Color().parseCSS("#ff2a1e");
|
|
192
|
+
const mixed = new Color();
|
|
193
|
+
|
|
194
|
+
const shield = new ProgressBar(x, y, {
|
|
195
|
+
width: 190, height: 13,
|
|
196
|
+
trackColor: null, // hollow: the scene shows through
|
|
197
|
+
borderColor: "rgba(122, 190, 235, 0.8)",
|
|
198
|
+
padding: 2,
|
|
199
|
+
fillColor: mixed, // KEPT, not copied
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// each frame
|
|
203
|
+
mixed.copy(empty).lerp(full, hp); // the bar follows, and so can a shader
|
|
204
|
+
shield.value = hp;
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Blinking is the same story: `setOpacity()` already does it, on whatever clock
|
|
208
|
+
the game is already keeping. Neither is built in.
|
|
209
|
+
|
|
210
|
+
**`bindEvent` takes the value from an event instead**, and the subscription
|
|
211
|
+
then lives exactly as long as the bar:
|
|
212
|
+
|
|
213
|
+
```js
|
|
214
|
+
const bar = new ProgressBar(0, y, {
|
|
215
|
+
width: renderer.width, height: 4,
|
|
216
|
+
trackColor: "black", fillColor: "#55aa00",
|
|
217
|
+
bindEvent: event.LOADER_PROGRESS,
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Hold that subscription anywhere else and it outlives the bar, firing into a
|
|
222
|
+
renderable whose `pos` has already been released. The engine's own loading
|
|
223
|
+
screen is built on exactly this.
|
|
224
|
+
|
|
225
|
+
Two more worth knowing:
|
|
226
|
+
|
|
227
|
+
- **The border is four filled rects, not a stroke** (unless the bar is
|
|
228
|
+
rounded). A stroke is centred on the path, so half of it falls outside and a
|
|
229
|
+
bordered bar paints over its neighbour; and `strokeRect` adds corner joins
|
|
230
|
+
only above a line width of 1, so at exactly 1 a corner pixel goes missing.
|
|
231
|
+
- **`trackColor: null` leaves the bar hollow**, which is what a HUD over a busy
|
|
232
|
+
scene usually wants: the border is then the only chrome.
|
|
233
|
+
|
|
132
234
|
### Buttons: extend the handlers, do not bind listeners
|
|
133
235
|
|
|
134
236
|
`UISpriteElement` is a `Sprite` that already registers itself for pointer
|
|
@@ -139,7 +241,7 @@ events, so a button is made by overriding methods rather than by wiring
|
|
|
139
241
|
|---|---|---|
|
|
140
242
|
| `onClick(event)` | pressed | `false` to stop the event propagating |
|
|
141
243
|
| `onRelease(event)` | pressed and released | `false` to stop propagating |
|
|
142
|
-
| `onOver(event)` | pointer enters |
|
|
244
|
+
| `onOver(event)` | pointer enters | `false` to stop propagating |
|
|
143
245
|
| `onOut(event)` | pointer leaves | — |
|
|
144
246
|
| `onHold()` | pressed and held | — |
|
|
145
247
|
|
|
@@ -163,6 +265,59 @@ default on a plain `Renderable` — is skipped by the broadphase and receives
|
|
|
163
265
|
nothing. `UISpriteElement` and `UIBaseElement` clear it for you; anything else
|
|
164
266
|
you make clickable has to clear it itself.
|
|
165
267
|
|
|
268
|
+
### `z` is container-local
|
|
269
|
+
|
|
270
|
+
`addChild(child, z)` writes a depth that means something **only among that
|
|
271
|
+
container's own children**. `autoDepth` numbers them from 1, so a button at
|
|
272
|
+
`z = 8` inside one panel and a whole second panel at `z = 2` are not comparable
|
|
273
|
+
numbers, and the second panel is still the one on top. Drawing and hit-testing
|
|
274
|
+
both resolve a cross-container pair the same way: walk up to the common parent
|
|
275
|
+
and compare the two siblings there.
|
|
276
|
+
|
|
277
|
+
So a panel is raised by raising **the panel**, not its contents:
|
|
278
|
+
|
|
279
|
+
```js
|
|
280
|
+
this.ancestor.moveToTop(panel); // reorders, and sets z past its neighbour
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Giving a child a huge `z` to "put it in front" lifts it only within its own
|
|
284
|
+
panel. This is also why a widget's `z` never has to be coordinated with
|
|
285
|
+
anything outside its own container.
|
|
286
|
+
|
|
287
|
+
### An opaque panel has to say so
|
|
288
|
+
|
|
289
|
+
The hit test asks the topmost renderable first and then keeps walking down, so
|
|
290
|
+
consuming is what stops a widget underneath answering too. A panel that can
|
|
291
|
+
overlap another one therefore wants both:
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
class Panel extends UIBaseElement {
|
|
295
|
+
onClick() {
|
|
296
|
+
this.ancestor.moveToTop(this); // and bring it to the front
|
|
297
|
+
return false; // consumed
|
|
298
|
+
}
|
|
299
|
+
onOver() {
|
|
300
|
+
return false; // the frame the pointer crosses in
|
|
301
|
+
}
|
|
302
|
+
onActivateEvent() {
|
|
303
|
+
super.onActivateEvent();
|
|
304
|
+
// and every frame after that, when the pointer is ALREADY inside and
|
|
305
|
+
// `onOver` no longer fires
|
|
306
|
+
input.registerPointerEvent("pointermove", this, () => false);
|
|
307
|
+
}
|
|
308
|
+
onDeactivateEvent() {
|
|
309
|
+
input.releasePointerEvent("pointermove", this);
|
|
310
|
+
super.onDeactivateEvent();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Leave `onOut` alone: an element that suppresses its own leave stays lit after
|
|
316
|
+
the pointer has gone. It fires for the covered element too, not only when the
|
|
317
|
+
pointer leaves its bounds, so a button half under the panel goes dark as soon as
|
|
318
|
+
the pointer slides onto the panel, which never takes it out of the button's
|
|
319
|
+
bounds.
|
|
320
|
+
|
|
166
321
|
### In a 3D scene, a HUD needs a SMALL depth
|
|
167
322
|
|
|
168
323
|
`floating` opts a renderable out of the camera transform. It does **not** opt it
|
|
@@ -187,3 +342,9 @@ Give a HUD the huge z that would put it on top in 2D and it lands at the far end
|
|
|
187
342
|
of the level instead, with the scenery drawing over it. Both shipped idioms are
|
|
188
343
|
the same rule: afterBurner's HUD sits at `-150`, and the glTF, Billboard, Night
|
|
189
344
|
City and Instanced Forest examples park a floating sky at `-10000` or `100000`.
|
|
345
|
+
|
|
346
|
+
## Related skills
|
|
347
|
+
|
|
348
|
+
- `melonjs-scenes-and-state` — `Tween` and the easing families, for animating any of this
|
|
349
|
+
- `melonjs-input` — which object gets a pointer event, and how to consume it
|
|
350
|
+
- `melonjs-loading-assets` — web fonts have to be loaded before a `Text` bakes
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Color-space bridge for glTF material factors.
|
|
3
|
-
*
|
|
4
|
-
* glTF 2.0 defines `pbrMetallicRoughness.baseColorFactor` in **linear** space
|
|
5
|
-
* (spec §3.9.2), while a melonJS `tint` is an 8-bit **sRGB** value — the same
|
|
6
|
-
* space as a CSS color or a texel out of a PNG. Handing the linear number
|
|
7
|
-
* straight to `tint.setColor(f * 255)` therefore displays every untextured
|
|
8
|
-
* glTF material far too light and desaturated: a linear `0.29` shows up as
|
|
9
|
-
* sRGB `0.58`, so an authored mid-green renders as pale mint.
|
|
10
|
-
*
|
|
11
|
-
* The encode below is the standard sRGB transfer function.
|
|
12
|
-
* @module level/gltf/srgb
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Encode one linear channel (0..1) to an 8-bit sRGB value (0..255).
|
|
16
|
-
* @param {number} c - linear channel value
|
|
17
|
-
* @returns {number} the sRGB-encoded channel, rounded to 0..255
|
|
18
|
-
*/
|
|
19
|
-
export function linearToSrgb8(c: number): number;
|
|
20
|
-
//# sourceMappingURL=srgb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"srgb.d.ts","sourceRoot":"","sources":["../../../src/level/gltf/srgb.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;GAIG;AACH,iCAHW,MAAM,GACJ,MAAM,CAQlB"}
|