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.
- package/README.md +2 -1
- package/build/camera/camera2d.d.ts +2 -0
- package/build/camera/camera2d.d.ts.map +1 -1
- package/build/camera/effects/fade_effect.d.ts.map +1 -1
- package/build/geometries/ellipse.d.ts +3 -0
- package/build/geometries/ellipse.d.ts.map +1 -1
- package/build/geometries/line.d.ts.map +1 -1
- package/build/geometries/polygon.d.ts +2 -1
- package/build/geometries/polygon.d.ts.map +1 -1
- package/build/index.d.ts +13 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5409 -1500
- package/build/index.js.map +4 -4
- package/build/input/gamepad.d.ts.map +1 -1
- package/build/input/pointerevent.d.ts.map +1 -1
- package/build/level/tiled/TMXLayer.d.ts +48 -14
- package/build/level/tiled/TMXLayer.d.ts.map +1 -1
- package/build/level/tiled/TMXTileMap.d.ts +1 -1
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/level/tiled/TMXTileset.d.ts.map +1 -1
- package/build/level/tiled/TMXUtils.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXRenderer.d.ts +1 -1
- package/build/level/tiled/renderer/TMXRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXStaggeredRenderer.d.ts.map +1 -1
- package/build/loader/loader.d.ts +55 -11
- package/build/loader/loader.d.ts.map +1 -1
- package/build/math/color.d.ts.map +1 -1
- package/build/math/math.d.ts +6 -1
- package/build/math/math.d.ts.map +1 -1
- package/build/math/observableVector2d.d.ts +6 -6
- package/build/math/observableVector2d.d.ts.map +1 -1
- package/build/math/observableVector3d.d.ts +8 -8
- package/build/math/observableVector3d.d.ts.map +1 -1
- package/build/particles/emitter.d.ts +15 -3
- package/build/particles/emitter.d.ts.map +1 -1
- package/build/particles/particle.d.ts +6 -0
- package/build/particles/particle.d.ts.map +1 -1
- package/build/particles/settings.d.ts +22 -5
- package/build/particles/settings.d.ts.map +1 -1
- package/build/physics/builtin/body.d.ts +14 -4
- package/build/physics/builtin/body.d.ts.map +1 -1
- package/build/physics/builtin/raycast.d.ts.map +1 -1
- package/build/physics/world.d.ts.map +1 -1
- package/build/renderable/container.d.ts +40 -6
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/frameAnimation.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +4 -2
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/text/bitmaptext.d.ts +12 -3
- package/build/renderable/text/bitmaptext.d.ts.map +1 -1
- package/build/renderable/text/text.d.ts +147 -4
- package/build/renderable/text/text.d.ts.map +1 -1
- package/build/renderable/text/textmetrics.d.ts +10 -2
- package/build/renderable/text/textmetrics.d.ts.map +1 -1
- package/build/renderable/text/textstyle.d.ts.map +1 -1
- package/build/renderable/ui/panelpaint.d.ts +5 -1
- package/build/renderable/ui/panelpaint.d.ts.map +1 -1
- package/build/renderable/ui/progressbar.d.ts +267 -95
- package/build/renderable/ui/progressbar.d.ts.map +1 -1
- package/build/renderable/ui/uibaseelement.d.ts +436 -50
- package/build/renderable/ui/uibaseelement.d.ts.map +1 -1
- package/build/renderable/ui/uicheckbox.d.ts +383 -0
- package/build/renderable/ui/uicheckbox.d.ts.map +1 -0
- package/build/renderable/ui/uifocus.d.ts +6 -0
- package/build/renderable/ui/uifocus.d.ts.map +1 -0
- package/build/renderable/ui/uilabel.d.ts +31 -0
- package/build/renderable/ui/uilabel.d.ts.map +1 -0
- package/build/renderable/ui/uipanel.d.ts +589 -116
- package/build/renderable/ui/uipanel.d.ts.map +1 -1
- package/build/renderable/ui/uiskin.d.ts +25 -0
- package/build/renderable/ui/uiskin.d.ts.map +1 -0
- package/build/renderable/ui/uislider.d.ts +518 -0
- package/build/renderable/ui/uislider.d.ts.map +1 -0
- package/build/renderable/ui/uispriteelement.d.ts +161 -85
- package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
- package/build/renderable/ui/uitextbutton.d.ts +369 -63
- package/build/renderable/ui/uitextbutton.d.ts.map +1 -1
- package/build/state/stage.d.ts.map +1 -1
- package/build/system/pool.d.ts.map +1 -1
- package/build/system/save.d.ts +2 -1
- package/build/system/save.d.ts.map +1 -1
- package/build/tweens/tween.d.ts +5 -2
- package/build/tweens/tween.d.ts.map +1 -1
- package/build/utils/fetchdata.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +0 -5
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/renderer.d.ts +20 -4
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/renderstate.d.ts +26 -3
- package/build/video/renderstate.d.ts.map +1 -1
- package/build/video/utils/tessellation.d.ts +11 -0
- package/build/video/utils/tessellation.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +3 -6
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/build/video/webgpu/batchers/primitive_batcher.d.ts.map +1 -1
- package/build/video/webgpu/webgpu_renderer.d.ts +3 -6
- package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/melonjs/SKILL.md +3 -3
- package/skills/melonjs-audio/SKILL.md +7 -5
- package/skills/melonjs-camera-and-drawing/SKILL.md +41 -1
- package/skills/melonjs-effects-and-shaders/SKILL.md +1 -0
- package/skills/melonjs-events/SKILL.md +3 -1
- package/skills/melonjs-getting-started/SKILL.md +1 -2
- package/skills/melonjs-input/SKILL.md +38 -2
- package/skills/melonjs-loading-assets/SKILL.md +53 -12
- package/skills/melonjs-math/SKILL.md +14 -3
- package/skills/melonjs-particles-and-trails/SKILL.md +72 -8
- package/skills/melonjs-physics/SKILL.md +53 -4
- package/skills/melonjs-plugins/SKILL.md +7 -2
- package/skills/melonjs-renderables/SKILL.md +7 -0
- package/skills/melonjs-scenes-and-state/SKILL.md +15 -0
- package/skills/melonjs-sprites-and-animation/SKILL.md +14 -0
- package/skills/melonjs-tilemaps/SKILL.md +96 -2
- 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:
|
|
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 |
|