melonjs 20.6.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 +10 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +23361 -20195
- 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/lang/deprecated.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 +36 -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/lighting/light2d.d.ts +68 -2
- package/build/lighting/light2d.d.ts.map +1 -1
- package/build/lighting/light3d.d.ts.map +1 -1
- package/build/loader/loader.d.ts +63 -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/fontface.d.ts +2 -0
- package/build/loader/parsers/fontface.d.ts.map +1 -1
- package/build/loader/parsers/mtl.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 +152 -3
- package/build/physics/adapter.d.ts.map +1 -1
- package/build/physics/builtin/body.d.ts +9 -18
- 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/sat.d.ts.map +1 -1
- package/build/physics/builtin/sat3d.d.ts +46 -0
- package/build/physics/builtin/sat3d.d.ts.map +1 -1
- package/build/physics/physicseditor.d.ts +2 -0
- package/build/physics/physicseditor.d.ts.map +1 -0
- 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 +14 -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 +306 -5
- 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 +129 -28
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +77 -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 +39 -14
- 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/state/stage.d.ts +22 -0
- package/build/state/stage.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/buffer/vertex.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/meshmaterial.d.ts +2 -0
- package/build/video/gpu/meshmaterial.d.ts.map +1 -0
- 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 +13 -1
- 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 +2 -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/shaders/multitexture-lit.d.ts.map +1 -1
- 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/lit_quad_batcher.d.ts +17 -0
- package/build/video/webgpu/batchers/lit_quad_batcher.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/texture/store.d.ts.map +1 -1
- package/build/video/webgpu/webgpu_renderer.d.ts +8 -75
- package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/melonjs-3d/SKILL.md +293 -19
- package/skills/melonjs-3d-assets/SKILL.md +123 -13
- 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-lighting/SKILL.md +45 -1
- package/skills/melonjs-loading-assets/SKILL.md +1 -1
- package/skills/melonjs-particles-and-trails/SKILL.md +106 -4
- package/skills/melonjs-performance/SKILL.md +79 -2
- package/skills/melonjs-physics/SKILL.md +420 -29
- package/skills/melonjs-renderables/SKILL.md +15 -1
- package/skills/melonjs-scenes-and-state/SKILL.md +121 -1
- package/skills/melonjs-tilemaps/SKILL.md +9 -0
- 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-scenes-and-state
|
|
3
|
-
description: "Use this skill for scene structure and game flow in melonJS — Stage subclasses, the state manager, transitions, pausing, the update loop, timers and tweens. Covers onResetEvent versus the constructor, state.set before state.change, the camera and world lifecycle per stage, and pause-aware timing. Triggers on: Stage, state, state.set, state.change, state.transition, state.pause, onResetEvent, onDestroyEvent, onActivateEvent, onDeactivateEvent, PLAY, MENU, LOADING, update loop, GAME_UPDATE, timer, setTimeout, setInterval, Tween, freeze."
|
|
3
|
+
description: "Use this skill for scene structure and game flow in melonJS — Stage subclasses, the state manager, transitions, pausing, the update loop, timers and tweens. Covers onResetEvent versus the constructor, state.set before state.change, the camera and world lifecycle per stage, and pause-aware timing. Triggers on: Tween, easing, fade out, flash, pulse, punch, shrink back, ease in, ease out, animate over time, countdown in update, Stage, state, state.set, state.change, state.transition, state.pause, onResetEvent, onDestroyEvent, onActivateEvent, onDeactivateEvent, PLAY, MENU, LOADING, update loop, GAME_UPDATE, timer, setTimeout, setInterval, Tween, freeze."
|
|
4
4
|
license: MIT
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -165,6 +165,18 @@ Returning nothing is falsy and the object can appear frozen while its state move
|
|
|
165
165
|
`dt` is milliseconds since the last frame and is the right basis for motion —
|
|
166
166
|
the engine already paces it. Do not reach for `performance.now()`.
|
|
167
167
|
|
|
168
|
+
**Smooth a value toward a target with `math.damp`, not with `lerp` per
|
|
169
|
+
frame.** `lerp(current, target, 0.1)` once per frame moves further on a slow
|
|
170
|
+
frame than on a fast one, so the feel drifts with the frame rate:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
this.speed = math.damp(this.speed, targetSpeed, 5, dt / 1000);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`damp(current, target, lambda, dt)` takes SECONDS, so divide `dt`. Higher
|
|
177
|
+
`lambda` converges faster. See `melonjs-camera-and-drawing` for the camera's
|
|
178
|
+
own `follow()` damping, which is already frame-rate independent for you.
|
|
179
|
+
|
|
168
180
|
A common idiom for a per-frame game controller with nothing to draw is a
|
|
169
181
|
`Renderable(0, 0, 1, 1)` with `alwaysUpdate = true` and an empty `draw()`.
|
|
170
182
|
|
|
@@ -191,6 +203,59 @@ countdown that should not freeze needs. (That argument was ignored by
|
|
|
191
203
|
|
|
192
204
|
## Tweens
|
|
193
205
|
|
|
206
|
+
### You are hand-rolling a tween if you write this
|
|
207
|
+
|
|
208
|
+
The shape, in any of its spellings. If you are adding a field that counts
|
|
209
|
+
milliseconds and dividing it by a constant to get a `0..1`, stop:
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
// ✗ a tween, written out longhand
|
|
213
|
+
private flashMs = 0;
|
|
214
|
+
// ... in update(dt)
|
|
215
|
+
if (this.flashMs > 0) {
|
|
216
|
+
this.flashMs -= dt;
|
|
217
|
+
const k = this.flashMs / FLASH_MS; // ← the 0..1
|
|
218
|
+
effect.setUniform("uIntensity", k * k); // ← and a curve, by hand
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
// ✓ the same thing
|
|
224
|
+
const driver = { k: 1 };
|
|
225
|
+
new Tween(driver)
|
|
226
|
+
.to({ k: 0 }, { duration: FLASH_MS })
|
|
227
|
+
.easing(Tween.Easing.Quadratic.In) // the curve, named
|
|
228
|
+
.onUpdate(() => effect.setUniform("uIntensity", driver.k))
|
|
229
|
+
.start();
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
The tells, any one of which is enough: a `*Ms` or `*Age` field that only
|
|
233
|
+
`update()` touches; a division by a `*_MS` constant; `k * k`, `(1 - k) ** 2` or
|
|
234
|
+
`** 1.4` written inline, which is an easing curve spelled by hand; an
|
|
235
|
+
`if (x <= 0)` arm that exists only to clean up at the end, which is
|
|
236
|
+
`onComplete`; a second timer counting the same duration to chain what happens
|
|
237
|
+
next, which is `delay`.
|
|
238
|
+
|
|
239
|
+
It matters beyond tidiness: a hand-rolled fade needs something to tick it, and
|
|
240
|
+
an effect that is NOT a renderable (one living on the camera, say) has nothing
|
|
241
|
+
that will. That forces an `update(dt)` method and a call site in the game loop
|
|
242
|
+
whose only job is to drive the fade. A tween updates itself, so both disappear.
|
|
243
|
+
|
|
244
|
+
### When NOT to reach for one
|
|
245
|
+
|
|
246
|
+
Four shapes that look similar and are not tweens:
|
|
247
|
+
|
|
248
|
+
| shape | what it is | use |
|
|
249
|
+
| --- | --- | --- |
|
|
250
|
+
| approaching a value that keeps MOVING | a follow, not an animation | `math.damp` |
|
|
251
|
+
| a loop that never ends | oscillation | a sine of your own clock |
|
|
252
|
+
| a gate: cooldown, spawn interval, invulnerability window | a timer, nothing is interpolated | a plain countdown |
|
|
253
|
+
| the same effect on dozens of live objects | per-instance churn | a hand-rolled countdown really is cheaper |
|
|
254
|
+
|
|
255
|
+
The rule in one line: **fixed duration, known endpoint, one-shot, few
|
|
256
|
+
instances.** All four, or it is not a tween.
|
|
257
|
+
|
|
258
|
+
|
|
194
259
|
```js
|
|
195
260
|
import { Tween, pool } from "melonjs";
|
|
196
261
|
|
|
@@ -216,6 +281,61 @@ Four traps:
|
|
|
216
281
|
- **Stop a tween before destroying its target**, or `onUpdate` fires against a
|
|
217
282
|
dead renderable.
|
|
218
283
|
|
|
284
|
+
**To animate something that is not a property, tween a holder and push the
|
|
285
|
+
value in `onUpdate`.** A shader uniform and a light's intensity are both set
|
|
286
|
+
through a method, so there is nothing for `to()` to interpolate directly. The
|
|
287
|
+
callback is invoked with the tweened object as `this` and the eased progress
|
|
288
|
+
`0..1` as its argument:
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
const fade = { level: 1 };
|
|
292
|
+
pool.pull("Tween", fade)
|
|
293
|
+
.to({ level: 0 }, { duration: 400 })
|
|
294
|
+
.easing(Tween.Easing.Quadratic.Out)
|
|
295
|
+
.onUpdate(function () {
|
|
296
|
+
effect.setUniform("uIntensity", this.level);
|
|
297
|
+
muzzleLight.intensity = this.level * 3;
|
|
298
|
+
})
|
|
299
|
+
.start();
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Use a `function`, not an arrow, if you want `this` to be the tweened object;
|
|
303
|
+
an arrow keeps the enclosing `this` and you read the holder by name instead.
|
|
304
|
+
For a handful of pooled objects a hand-rolled countdown in `update()` is
|
|
305
|
+
cheaper than a `Tween` each — this is the right tool for one-off effects, not
|
|
306
|
+
for every particle.
|
|
307
|
+
|
|
308
|
+
### Pick the easing, not just the duration
|
|
309
|
+
|
|
310
|
+
Eleven families, each with `In`, `Out` and `InOut`. `Out` is what most UI
|
|
311
|
+
wants: the value arrives decisively instead of creeping in. The two worth
|
|
312
|
+
knowing by name beyond the power curves:
|
|
313
|
+
|
|
314
|
+
| family | what it does |
|
|
315
|
+
| --- | --- |
|
|
316
|
+
| `Back` | **overshoots past the target and settles back**, which is impact: a stamp, a button press, anything that should LAND rather than arrive |
|
|
317
|
+
| `Bounce` | lands and bounces, for something dropping onto a surface |
|
|
318
|
+
|
|
319
|
+
```js
|
|
320
|
+
// a stamp: scale falls to 1 and springs through it
|
|
321
|
+
const driver = { scale: 5 };
|
|
322
|
+
new Tween(driver)
|
|
323
|
+
.to({ scale: 1 }, { duration: 420 })
|
|
324
|
+
.easing(Tween.Easing.Back.Out)
|
|
325
|
+
.onUpdate(() => { label.currentTransform.identity(); label.scale(driver.scale); })
|
|
326
|
+
.onComplete(() => camera.shake(12, 400)) // the thump, when it truly lands
|
|
327
|
+
.start();
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
`Back` and `Elastic` **leave the range** between your start and end, so clamp
|
|
331
|
+
anything that cannot take it, an opacity or a colour channel above all. The
|
|
332
|
+
overshoot follows the direction of travel: a value tweened DOWN overshoots
|
|
333
|
+
below its target.
|
|
334
|
+
|
|
335
|
+
Reach for `onComplete` for anything that must happen on arrival, rather than a
|
|
336
|
+
second timer counting the same duration. `delay` in the `to()` options chains
|
|
337
|
+
the next one without a timer either.
|
|
338
|
+
|
|
219
339
|
## Guard teardown-adjacent callbacks
|
|
220
340
|
|
|
221
341
|
Callbacks can fire while a stage is being torn down, when the current state is
|
|
@@ -100,6 +100,15 @@ melonJS pre-registers `Renderable`, `Sprite`, `NineSliceSprite`, `Text`,
|
|
|
100
100
|
`BitmapText`, `ImageLayer`, `ColorLayer`, `Light2d`, `Collectable` and `Trigger`
|
|
101
101
|
as Tiled classes, so `Collectable` and `Trigger` work out of the box.
|
|
102
102
|
|
|
103
|
+
A `Trigger` forwards a **fixed list** of settings to `level.load()` — not
|
|
104
|
+
whatever you pass it. Today that list is `container`, `onLoaded`, `flatten`,
|
|
105
|
+
`setViewportBounds` and the glTF scene options (`scale`, `rightHanded`,
|
|
106
|
+
`lights`, `lightIntensityScale`, `castGroundShadow`, `shadowGroundY`); see the
|
|
107
|
+
3D assets skill. Anything outside it is **dropped silently**, which is worth
|
|
108
|
+
knowing before you spend an afternoon on a map that loads at the wrong scale.
|
|
109
|
+
`async` is excluded deliberately — the trigger needs to sequence its own
|
|
110
|
+
transition.
|
|
111
|
+
|
|
103
112
|
## Camera bounds
|
|
104
113
|
|
|
105
114
|
`level.load` sets the viewport bounds to the map size for you —
|
|
@@ -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"}
|