melonjs 20.12.0 → 20.13.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 (120) hide show
  1. package/README.md +2 -1
  2. package/build/camera/camera2d.d.ts +2 -0
  3. package/build/camera/camera2d.d.ts.map +1 -1
  4. package/build/camera/effects/fade_effect.d.ts.map +1 -1
  5. package/build/geometries/ellipse.d.ts +3 -0
  6. package/build/geometries/ellipse.d.ts.map +1 -1
  7. package/build/geometries/line.d.ts.map +1 -1
  8. package/build/geometries/polygon.d.ts +2 -1
  9. package/build/geometries/polygon.d.ts.map +1 -1
  10. package/build/index.d.ts +13 -2
  11. package/build/index.d.ts.map +1 -1
  12. package/build/index.js +5409 -1500
  13. package/build/index.js.map +4 -4
  14. package/build/input/gamepad.d.ts.map +1 -1
  15. package/build/input/pointerevent.d.ts.map +1 -1
  16. package/build/level/tiled/TMXLayer.d.ts +48 -14
  17. package/build/level/tiled/TMXLayer.d.ts.map +1 -1
  18. package/build/level/tiled/TMXTileMap.d.ts +1 -1
  19. package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
  20. package/build/level/tiled/TMXTileset.d.ts.map +1 -1
  21. package/build/level/tiled/TMXUtils.d.ts.map +1 -1
  22. package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts.map +1 -1
  23. package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts.map +1 -1
  24. package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts.map +1 -1
  25. package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts.map +1 -1
  26. package/build/level/tiled/renderer/TMXRenderer.d.ts +1 -1
  27. package/build/level/tiled/renderer/TMXRenderer.d.ts.map +1 -1
  28. package/build/level/tiled/renderer/TMXStaggeredRenderer.d.ts.map +1 -1
  29. package/build/loader/loader.d.ts +55 -11
  30. package/build/loader/loader.d.ts.map +1 -1
  31. package/build/math/color.d.ts.map +1 -1
  32. package/build/math/math.d.ts +6 -1
  33. package/build/math/math.d.ts.map +1 -1
  34. package/build/math/observableVector2d.d.ts +6 -6
  35. package/build/math/observableVector2d.d.ts.map +1 -1
  36. package/build/math/observableVector3d.d.ts +8 -8
  37. package/build/math/observableVector3d.d.ts.map +1 -1
  38. package/build/particles/emitter.d.ts +15 -3
  39. package/build/particles/emitter.d.ts.map +1 -1
  40. package/build/particles/particle.d.ts +6 -0
  41. package/build/particles/particle.d.ts.map +1 -1
  42. package/build/particles/settings.d.ts +22 -5
  43. package/build/particles/settings.d.ts.map +1 -1
  44. package/build/physics/builtin/body.d.ts +14 -4
  45. package/build/physics/builtin/body.d.ts.map +1 -1
  46. package/build/physics/builtin/raycast.d.ts.map +1 -1
  47. package/build/physics/world.d.ts.map +1 -1
  48. package/build/renderable/container.d.ts +40 -6
  49. package/build/renderable/container.d.ts.map +1 -1
  50. package/build/renderable/frameAnimation.d.ts.map +1 -1
  51. package/build/renderable/renderable.d.ts.map +1 -1
  52. package/build/renderable/sprite.d.ts +4 -2
  53. package/build/renderable/sprite.d.ts.map +1 -1
  54. package/build/renderable/text/bitmaptext.d.ts +12 -3
  55. package/build/renderable/text/bitmaptext.d.ts.map +1 -1
  56. package/build/renderable/text/text.d.ts +147 -4
  57. package/build/renderable/text/text.d.ts.map +1 -1
  58. package/build/renderable/text/textmetrics.d.ts +10 -2
  59. package/build/renderable/text/textmetrics.d.ts.map +1 -1
  60. package/build/renderable/text/textstyle.d.ts.map +1 -1
  61. package/build/renderable/ui/panelpaint.d.ts +5 -1
  62. package/build/renderable/ui/panelpaint.d.ts.map +1 -1
  63. package/build/renderable/ui/progressbar.d.ts +267 -95
  64. package/build/renderable/ui/progressbar.d.ts.map +1 -1
  65. package/build/renderable/ui/uibaseelement.d.ts +436 -50
  66. package/build/renderable/ui/uibaseelement.d.ts.map +1 -1
  67. package/build/renderable/ui/uicheckbox.d.ts +383 -0
  68. package/build/renderable/ui/uicheckbox.d.ts.map +1 -0
  69. package/build/renderable/ui/uifocus.d.ts +6 -0
  70. package/build/renderable/ui/uifocus.d.ts.map +1 -0
  71. package/build/renderable/ui/uilabel.d.ts +31 -0
  72. package/build/renderable/ui/uilabel.d.ts.map +1 -0
  73. package/build/renderable/ui/uipanel.d.ts +589 -116
  74. package/build/renderable/ui/uipanel.d.ts.map +1 -1
  75. package/build/renderable/ui/uiskin.d.ts +25 -0
  76. package/build/renderable/ui/uiskin.d.ts.map +1 -0
  77. package/build/renderable/ui/uislider.d.ts +518 -0
  78. package/build/renderable/ui/uislider.d.ts.map +1 -0
  79. package/build/renderable/ui/uispriteelement.d.ts +161 -85
  80. package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
  81. package/build/renderable/ui/uitextbutton.d.ts +369 -63
  82. package/build/renderable/ui/uitextbutton.d.ts.map +1 -1
  83. package/build/state/stage.d.ts.map +1 -1
  84. package/build/system/pool.d.ts.map +1 -1
  85. package/build/system/save.d.ts +2 -1
  86. package/build/system/save.d.ts.map +1 -1
  87. package/build/tweens/tween.d.ts +5 -2
  88. package/build/tweens/tween.d.ts.map +1 -1
  89. package/build/utils/fetchdata.d.ts.map +1 -1
  90. package/build/video/canvas/canvas_renderer.d.ts +0 -5
  91. package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
  92. package/build/video/renderer.d.ts +20 -4
  93. package/build/video/renderer.d.ts.map +1 -1
  94. package/build/video/renderstate.d.ts +26 -3
  95. package/build/video/renderstate.d.ts.map +1 -1
  96. package/build/video/utils/tessellation.d.ts +11 -0
  97. package/build/video/utils/tessellation.d.ts.map +1 -1
  98. package/build/video/webgl/webgl_renderer.d.ts +3 -6
  99. package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
  100. package/build/video/webgpu/batchers/primitive_batcher.d.ts.map +1 -1
  101. package/build/video/webgpu/webgpu_renderer.d.ts +3 -6
  102. package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
  103. package/package.json +1 -1
  104. package/skills/melonjs/SKILL.md +3 -3
  105. package/skills/melonjs-audio/SKILL.md +7 -5
  106. package/skills/melonjs-camera-and-drawing/SKILL.md +41 -1
  107. package/skills/melonjs-effects-and-shaders/SKILL.md +1 -0
  108. package/skills/melonjs-events/SKILL.md +3 -1
  109. package/skills/melonjs-getting-started/SKILL.md +1 -2
  110. package/skills/melonjs-input/SKILL.md +38 -2
  111. package/skills/melonjs-loading-assets/SKILL.md +53 -12
  112. package/skills/melonjs-math/SKILL.md +14 -3
  113. package/skills/melonjs-particles-and-trails/SKILL.md +72 -8
  114. package/skills/melonjs-physics/SKILL.md +53 -4
  115. package/skills/melonjs-plugins/SKILL.md +7 -2
  116. package/skills/melonjs-renderables/SKILL.md +7 -0
  117. package/skills/melonjs-scenes-and-state/SKILL.md +15 -0
  118. package/skills/melonjs-sprites-and-animation/SKILL.md +14 -0
  119. package/skills/melonjs-tilemaps/SKILL.md +96 -2
  120. package/skills/melonjs-ui-and-text/SKILL.md +560 -23
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: melonjs-tilemaps
3
- description: "Use this skill for Tiled maps in melonJS — loading TMX/TSX levels, spawning entities from Tiled objects, collision shapes authored in Tiled, isometric and hexagonal maps, and image layers. Covers registerTiledObjectClass and the pool.register name contract, camera bounds, compressed maps needing the inflate plugin, and the level director API. Triggers on: Tiled, TMX, TSX, tilemap, level.load, level.load async, await level.load, tileset, ImageLayer, isometric, hexagonal, staggered, pool.register, Collectable, Trigger, object layer, collision layer, parallax, registerTiledObjectClass, registerTiledObjectFactory, TMXObject, resolvedProperty, resolvedProperties, tile class, tile properties."
3
+ description: "Use this skill for Tiled maps in melonJS — loading TMX/TSX levels, spawning entities from Tiled objects, collision shapes authored in Tiled, isometric and hexagonal maps, and image layers, and reading or changing tiles while the game runs. Covers registerTiledObjectClass and the pool.register name contract, camera bounds, compressed maps needing the inflate plugin, and the level director API. Triggers on: Tiled, TMX, TSX, tilemap, setTile, clearTile, cellAt, getTile, getTileById, change a tile, tile at run time, game board, grid, tile properties at run time, getTileProperties, map properties, level.load, level.load async, await level.load, tileset, ImageLayer, isometric, hexagonal, staggered, pool.register, Collectable, Trigger, object layer, collision layer, parallax, registerTiledObjectClass, registerTiledObjectFactory, TMXObject, resolvedProperty, resolvedProperties, tile class, tile properties."
4
4
  license: MIT
5
5
  ---
6
6
 
@@ -185,6 +185,90 @@ knowing before you spend an afternoon on a map that loads at the wrong scale.
185
185
  `async` is excluded deliberately — the trigger needs to sequence its own
186
186
  transition.
187
187
 
188
+ ## Reading and changing tiles at run time
189
+
190
+ A tile layer is a live grid, not just a picture: read it as the game board,
191
+ and change cells while the game runs — a door opening, a floor panel lighting
192
+ up, a wall blown away. A loaded tile layer is a `TMXLayer` in the world, under
193
+ the name it has in Tiled:
194
+
195
+ ```js
196
+ await level.load("map1", { container: this.app.world, async: true });
197
+ const board = this.app.world.getChildByName("ground")[0]; // a TMXLayer
198
+ board.cols; board.rows; // the grid, in cells
199
+ board.tilewidth; board.tileheight; // a cell, in pixels
200
+ ```
201
+
202
+ Two coordinate systems, and the methods do not share one:
203
+
204
+ | method | takes | returns |
205
+ |---|---|---|
206
+ | `cellAt(col, row)` | column and row | the `Tile` there, or `null` for an empty cell or outside the grid |
207
+ | `getTile(x, y)` | **world pixels** | the same `Tile` object `cellAt` gives, or `null` |
208
+ | `setTile(tile, col, row)` | column and row | puts `tile` there, and returns it |
209
+ | `clearTile(col, row)` | column and row | empties the cell: `cellAt` then returns `null` |
210
+ | `getTileById(gid, col, row)` | a global tile id, column and row | a new `Tile`, to pass to `setTile` |
211
+
212
+ Columns and rows are the map's tile coordinates, the ones Tiled shows. On an
213
+ **infinite** map a layer can hold tiles left of or above the map's origin:
214
+ there `board.startx` / `board.starty` are negative, its cells run from
215
+ `startx` to `startx + cols - 1` (and `starty` to `starty + rows - 1`), and
216
+ `cellAt(-3, -2)` is the tile Tiled shows at (-3, -2), drawn where Tiled draws
217
+ it. On a finite map both are 0:
218
+
219
+ ```js
220
+ for (let row = board.starty; row < board.starty + board.rows; row++) {
221
+ for (let col = board.startx; col < board.startx + board.cols; col++) {
222
+ const tile = board.cellAt(col, row); // every cell, infinite maps included
223
+ }
224
+ }
225
+ ```
226
+
227
+ The viewport bounds still cover only the map's `width` x `height`: set them
228
+ yourself to scroll to tiles painted outside it.
229
+
230
+ A `Tile` carries `tileId` (its **global** id), `col`, `row` and `tileset`.
231
+ Tiled shows a tile's *local* id in the tileset editor; the global id is
232
+ `tileset.firstgid + localId`, and only the global one works with `setTile`.
233
+ The tile's custom properties and class, set in Tiled's tileset editor, come
234
+ from its tileset by global id:
235
+
236
+ ```js
237
+ const tile = board.cellAt(col, row);
238
+ const props = tile && tile.tileset.getTileProperties(tile.tileId); // { kind: "floor" } or undefined
239
+ const cls = tile && tile.tileset.getTileClass(tile.tileId);
240
+ ```
241
+
242
+ To swap a cell for another tile of the tileset, build the tile and set it. Look
243
+ global ids up by property once, rather than hard-coding them, so a designer
244
+ can rearrange the tileset:
245
+
246
+ ```js
247
+ const tileset = board.tilesets.getTilesetByIndex(0); // the layer's first tileset
248
+ const gidByKind = new Map();
249
+ for (let gid = tileset.firstgid; gid <= tileset.lastgid; gid++) {
250
+ const kind = tileset.getTileProperties(gid)?.kind;
251
+ if (kind !== undefined) gidByKind.set(kind, gid);
252
+ }
253
+
254
+ // light a floor panel up
255
+ board.setTile(board.getTileById(gidByKind.get("floor-lit"), col, row), col, row);
256
+ // knock a wall down
257
+ board.clearTile(col, row);
258
+ ```
259
+
260
+ The layer redraws the changed cell by itself. What it does **not** change is
261
+ collision: solid ground comes from collision object layers (below), so a tile
262
+ set or cleared changes what is drawn and what `cellAt` returns, not what a body
263
+ runs into. Keep a layer you edit often off `preRender` (see the symptom table).
264
+
265
+ The map's own custom properties (Map → Map Properties in Tiled) are set on the
266
+ map object, which `level.getCurrentLevel()` returns once it is loaded: a
267
+ `theme` string property is `level.getCurrentLevel().theme`. They are set
268
+ **over** the map's own fields, so a property named like one replaces it: a
269
+ custom `name` property becomes the level's `name`. Give level settings names of
270
+ their own (`title`, not `name`).
271
+
188
272
  ## Camera bounds
189
273
 
190
274
  `level.load` sets the viewport bounds to the map size for you —
@@ -344,6 +428,7 @@ unanimated layer into the offscreen-bake path instead.
344
428
 
345
429
  | symptom | cause |
346
430
  |---|---|
431
+ | objects a screen added just before `level.load` draw in the order they were added (a background over everything) | before 20.13 the reset inside `level.load` dropped the sort still pending for the persistent children it kept; update, or call `sort()` on their container once the level is loaded |
347
432
  | a Tiled object becomes a plain shape with no behaviour | its class/name does not match any registered factory, or it was registered after `level.load` |
348
433
  | the world is still empty right after `level.load` | the load is deferred to a timer while the loop runs — `await level.load(id, { async: true })`, or use `onLoaded` / `LEVEL_LOADED` |
349
434
  | `await level.load(id)` returned `true` rather than a promise | without `async: true` the call returns a boolean; `await true` resolves immediately and the load has not run yet — pass the flag when you mean to await |
@@ -361,7 +446,16 @@ unanimated layer into the offscreen-bake path instead.
361
446
  | a property set on a tile is undefined on the object's `settings` | tile properties are not copied onto `settings`: read them with `settings.resolvedProperty(name)` |
362
447
  | objects placed from a classed tile come out as plain sprites | that class is not registered, it is a built-in name, or the object has a class or a registered name of its own, which come first |
363
448
  | missing tiles or a blank map | the `.tsx` or tileset image was not preloaded |
364
- | a tileset's transparent color (`trans`) still shows (the console says it could not be applied) | the image cannot be read back: one from another origin needs CORS headers on the server and `loader.setOptions({ crossOrigin: "anonymous" })` (without them WebGL and WebGPU cannot draw it at all), and a compressed texture cannot be changed: export it with an alpha channel instead |
449
+ | a tileset's transparent color (`trans`) still shows (the console says it could not be applied) | the image cannot be read back: an image the game made itself from another origin without CORS (an `<img>` with no `crossOrigin`) cannot be, so load it with the loader, which only loads an image another origin's server allows (its CORS headers) and can always read back; and a compressed texture cannot be changed: export it with an alpha channel instead |
450
+ | `cellAt` returns `null` (or the wrong tile) for a cell that has one | it was given pixels: `cellAt`, `setTile` and `clearTile` take column and row, only `getTile` takes world pixels |
451
+ | `setTile` shows the wrong tile, or nothing | it was given Tiled's local tile id: use the global id, `tileset.firstgid + localId`, through `getTileById` |
452
+ | an infinite map's tiles sit in the wrong row, or tiles left of or above the origin are missing | an older melonJS ignored where the chunks start (update); and loop from `layer.startx` / `layer.starty`, not 0, to reach cells left of or above the origin |
453
+ | on a staggered map `getTile` gives the neighbouring tile on every row but the first, or a scrolled view draws nothing | a bug of older melonJS versions in the staggered renderer: update |
454
+ | on an isometric (or staggered, oblique) map `getTile` gives an edge tile for a point just outside the tiles | an older melonJS rounded a fractional column or row toward 0: update |
455
+ | tiles of a second tileset draw from the first tileset's image (that first one has a `margin`) | an older melonJS let its gid range overrun into the next tileset (update): the range is the `tilecount` Tiled saved |
456
+ | a layer is `undefined` from `getChildByName(name)[0]` | the level is not in the world yet (await `level.load(id, { async: true })`), or the name differs from the layer's in Tiled |
457
+ | a tile set or cleared at run time does not block or free movement | tile layers carry no collision: collision comes from collision object layers |
458
+ | the level's `name` is not its id after loading | a map custom property named `name` replaced it: map properties are set over the map's own fields |
365
459
  | changing tiles at runtime is slow on a pre-rendered layer | outside an orthogonal map whose tiles fit their cells, a changed tile re-bakes the whole layer before it next draws: keep layers you edit often off `preRender` |
366
460
  | thin lines between tiles on the Canvas renderer, with smoothing on | filtering blends in the next tile of the tileset or its spacing, which a canvas cannot prevent: set `antiAlias: false`, or `preRender` the layer. WebGL and WebGPU keep each tile to itself |
367
461
  | tilemap slow on some machines | layer fell back off the shader path — check the console warning for the reason |