Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
824cae0
Tests: the MaskEffect drawing checks run on a WebGPU device
claude Nov 19, 2026
5a3557e
GPU tile layers for isometric maps: the shader render mode (#1897)
claude Nov 19, 2026
74c3e6c
GPU tile layers: blend soft tile edges, and hold both paths to a refe…
claude Nov 19, 2026
b5f1e0d
GPU tile layers: review fixes, shared orientation module, benchmark (…
claude Nov 19, 2026
3aa084e
Tiled: tile layers follow their offset, and are in view as far as the…
claude Nov 19, 2026
a3dd914
GPU tile layers for staggered and hexagonal maps (#1897)
claude Nov 19, 2026
3b89894
Tile layers: final review fixes (#1897)
claude Nov 19, 2026
2e78819
Tile layers: fixes from an adversarial test audit (#1897)
claude Nov 19, 2026
4ada8ff
Tile layers: the rest of the adversarial audit (#1897)
claude Nov 19, 2026
11e7899
Changelog: 20.17.0 rewritten for readers
claude Nov 19, 2026
33c1d20
README: GPU tile rendering covers isometric, staggered and hexagonal …
claude Nov 19, 2026
65ca9f0
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 19, 2026
9499ef0
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 19, 2026
a4647d0
Test: a sprite mask transition set for one change, then set back at once
claude Nov 19, 2026
2bb1fcc
Transitions: a sprite the game keeps for itself shapes every mask tra…
claude Nov 19, 2026
8f75798
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 19, 2026
60bf746
Tiled: object layers and group layers follow their offset
claude Nov 19, 2026
5396132
Platformer example: clear a stray offset on the flies layer of the se…
claude Nov 19, 2026
8e90cbd
Platformer examples: the same stray offset cleared in the source copi…
claude Nov 19, 2026
f60ed87
Platformer example: slimes leave a trail of slime
claude Nov 19, 2026
5737798
Platformer example: a pool of slime under the whole slime
claude Nov 19, 2026
66d0db2
Platformer (Matter) example: slimes stand in a pool of slime and leav…
claude Nov 19, 2026
c9730f4
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 19, 2026
4219d5c
Build: shader comments are no longer published
claude Nov 19, 2026
c3cfbd0
Docs: what a normal map needs, and where it is lit
claude Nov 19, 2026
b535246
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 19, 2026
43bd0f1
Dependencies: update the development tools flagged by the security audit
claude Nov 20, 2026
c3ecf31
Engine: check a type where it was asserted, in the places a stricter …
claude Nov 20, 2026
5654fee
Build: the engine is no longer linted by its own build
claude Nov 20, 2026
df87971
Lint: one package at a time, cached by Turborepo
claude Nov 20, 2026
1d21299
CI: keep Turborepo's cache between runs
claude Nov 20, 2026
fe2ab5e
Lint: a package is re-linted for another's published types, not for i…
claude Nov 20, 2026
f0d3990
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 20, 2026
50dd8f6
CI: Biome runs once in the lint job
claude Nov 20, 2026
0db9590
CI: the test job shares the lint job's caches
claude Nov 20, 2026
c964333
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 20, 2026
65e8a26
Tests: the browser keeps a module for the length of a one-shot run
claude Nov 20, 2026
62dde2e
Tests: the tile-layer benchmark runs when asked for, and watch mode r…
claude Nov 20, 2026
432693c
TEMPORARY: CI compares a run that re-validates its modules with one t…
claude Nov 20, 2026
cd2e86d
Changelog: the faster test suite, under Chore
claude Nov 20, 2026
48f011b
TEMPORARY: CI runs the test job twelve times and logs what a lost pag…
claude Nov 20, 2026
3a633b1
Remove the temporary CI comparison, and record what it showed
claude Nov 20, 2026
7bbce4e
CI: the test step no longer retries
claude Nov 20, 2026
f8d2b9c
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 20, 2026
1f60d1c
Effects: GradientMapEffect and DitherEffect, and a Dithering example
claude Nov 21, 2026
fdb87e4
Remove the Dithering example; the two effects in the README and the s…
claude Nov 21, 2026
f57b401
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 21, 2026
7339982
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 21, 2026
506c0ae
Changelog: a shorter Chore section for 20.17.0
claude Nov 21, 2026
f9a00ac
Small fixes for 20.17.0: package contents, mask transition warning, e…
claude Nov 21, 2026
a44c618
Fix rotated atlas frames and black frames after a capture; examples o…
claude Nov 21, 2026
45a7a23
Path2D: keep half-circle SVG arcs from turning into straight lines
SwastikTripathi Nov 21, 2026
16fab41
SVG Shapes example: a row of half-circle arcs
claude Nov 21, 2026
202b256
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 21, 2026
fde2b96
Merge pull request #1910: half-circle SVG arcs are drawn as arcs
claude Nov 21, 2026
64bac5c
Changelog: credit the contributor of the half-circle arc fix
claude Nov 21, 2026
5b26168
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 21, 2026
748ecaa
Changelog: trim 20.17.0 and credit a contributor
claude Nov 21, 2026
b35dd09
Changelog: the engine size entry, shorter, under Chore
claude Nov 21, 2026
68d4603
Changelog: shorter entries for 20.17.0
claude Nov 21, 2026
4dc6845
Effects: FlashEffect and TintPulseEffect are color matrices
claude Nov 21, 2026
74deda7
Release: melonJS 20.17.0
claude Nov 21, 2026
0f29993
Changelog: FlashEffect and TintPulseEffect on the color matrix shader…
claude Nov 21, 2026
de2f8e8
Changelog: the FlashEffect and TintPulseEffect entry, under Performance
claude Nov 21, 2026
403a888
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 21, 2026
c7372d6
Tiled: a layer's renderMode property takes effect, and one viewport h…
claude Nov 22, 2026
8c6b3b2
Levels: a format can be registered with the director; a custom loader…
claude Nov 22, 2026
0ce60c8
Tile layers: the format-neutral layer is its own class, TileLayer, wh…
claude Nov 22, 2026
e54118d
Tilesets: the format-neutral Tileset and TilesetGroup, which the Tile…
claude Nov 22, 2026
190101e
Tile maps: PlacedTileLayer draws tiles placed freely; tests for the f…
claude Nov 22, 2026
712efea
LDtk: a plugin that loads LDtk projects as they are saved, checked ag…
claude Nov 22, 2026
12ee025
LDtk: whole worlds, levels added and removed while the game runs; a t…
claude Nov 22, 2026
73b1b17
Examples: LDtk Level Loader, the twelve sample projects that come wit…
claude Nov 22, 2026
febb195
LDtk: tests on a project made for the purpose (other tile sizes, hidd…
claude Nov 22, 2026
ed04257
LDtk: built into the engine, no plugin
claude Nov 22, 2026
121961e
LDtk: tests that its grid layers are drawn by the GPU tile renderer
claude Nov 22, 2026
2c640cf
Levels: Tiled and LDtk add a level to a container with the same code,…
claude Nov 22, 2026
7ad0c4b
Levels: the collision layer convention and world shapes are one code …
claude Nov 22, 2026
b2ed857
LDtk: the level object reads as a Tiled map does, and the pathfinding…
claude Nov 22, 2026
ec4f86b
LDtk: skills, README example list and asset type table for the built-…
claude Nov 22, 2026
b556f75
LDtk: the types its classes refer to are exported, internals kept out…
claude Nov 22, 2026
7e4cda0
LDtk: a project that fails to load says what failed and leaves nothin…
claude Nov 22, 2026
6bd1562
LDtk: the engine's own warnOnce, canvas allocator, renderer factory a…
claude Nov 22, 2026
6d670e9
Tile maps: the tile class, the flip bits and the collision constant l…
claude Nov 22, 2026
d7712bd
Tile maps: the tile layer and the placed-tile layer share their view …
claude Nov 22, 2026
f5ed13e
LDtk: a hidden layer is kept and not shown, and entities take their l…
claude Nov 22, 2026
69dd0b3
LDtk: entities drawn by Sprite and NineSliceSprite, built only by the…
claude Nov 22, 2026
8a99d6e
LDtk: a tile is the one LDtk points at in the image; a tileset cuts i…
claude Nov 22, 2026
672af36
Loader: an asset can hold the assets it refers to; LDtk's images go t…
claude Nov 22, 2026
3b7f994
Tile maps: floating layers, tiles left of a layer's origin, and run-t…
claude Nov 22, 2026
239085e
LDtk: tests for what an audit could change without one failing
claude Nov 22, 2026
9986a4e
Tile maps: a camera with only an offset hands the renderer the shifte…
claude Nov 22, 2026
c81ef61
Tiled: a test of a layer's renderMode property where it matters, on W…
claude Nov 22, 2026
8622219
Examples: dragging and the wheel move the LDtk and Tiled map views
claude Nov 22, 2026
ea0da6f
README: LDtk among the supported tools
claude Nov 22, 2026
0aabc8f
LDtk: the format as LDtk's JSON schema defines it, and the table of c…
claude Nov 22, 2026
9a62200
Tile maps: a tile layer can follow the camera (parallax), and LDtk's …
claude Nov 22, 2026
8523340
Tiled: the checks a tile layer's parallax factor is held to
claude Nov 22, 2026
938a112
Tiled: a tile layer's parallax factor moves it with the camera
claude Nov 22, 2026
2051560
Changelog: 20.18.0 said shorter
claude Nov 22, 2026
0389d19
Changelogs: what a game sees, and no more
claude Nov 22, 2026
fb7531d
LDtk worlds: one depth at a time, entities kept or left out, referenc…
claude Nov 22, 2026
d353837
Examples: a platformer on LDtk's GridVania world
claude Nov 22, 2026
e2b9530
LDtk worlds: a persistent entity stays when its level goes; the examp…
claude Nov 22, 2026
b4c6d8e
LDtk: what a level's entities become are objects, as in the rest of t…
claude Nov 22, 2026
86c964d
Levels: an object is found by its level's id, and `objects` chooses w…
claude Nov 22, 2026
63cce1d
LDtk platformer: sorted into folders, and given some juice with the e…
claude Nov 22, 2026
845f518
Skills: building a world in LDtk and loading it, step by step
claude Nov 22, 2026
f394ba5
Examples: the LDtk Platformer's entries say what it shows
claude Nov 22, 2026
be63afd
Review: two defects fixed, duplicate logic folded
claude Nov 22, 2026
416c0c4
Review: tests for what had none, and test helpers that repeated each …
claude Nov 22, 2026
1dfe119
Tile layers scroll by a `ratio`, as an image layer does
claude Nov 22, 2026
e2e4abd
LDtk platformer: a ladder goes through the floor it is set in
claude Nov 22, 2026
ff5ba6a
LDtk platformer: a double jump
claude Nov 22, 2026
753573b
Changelog: what a tile layer's ratio means, in a few words
claude Nov 22, 2026
a7e01c4
Changelogs: shorter entries, and LDtk as built-in support for the format
claude Nov 22, 2026
842102e
Changelog: parallax on tile layers, through ratio
claude Nov 22, 2026
f75077d
Changelog: a Tiled layer's parallax factor is part of the new paralla…
claude Nov 22, 2026
567c15b
LDtk examples: the debug panel
claude Nov 22, 2026
7d1ad7d
Tiled: a tile layer with the collider property is solid
claude Nov 22, 2026
b3c3456
Sprite Fusion: its TMX export, tested as exported; its logo in the RE…
claude Nov 22, 2026
3aeb0d2
Sprite Fusion: the test fixture and the skill follow a real export
claude Nov 22, 2026
07d6785
Tile maps: "tilemap" and "spritefusion" asset types, attributes besid…
claude Nov 22, 2026
cf0b575
Tile layers: getProperties / setProperties for the tile in a cell
claude Nov 23, 2026
4bcfe27
Tile layers: getTileProperties / setTileProperties; pathfinding reads…
claude Nov 23, 2026
5a4e084
Docs: every asset type in one table; registerTiledObject* deprecated …
claude Nov 23, 2026
d6a9712
Review: a `ratio` property no longer breaks a tile layer; attributes,…
claude Nov 23, 2026
e35e904
Tile maps: the map renderers, the object registry and the map parser …
claude Nov 23, 2026
cf376a9
Rendering: the GPU tile layer renderers under a neutral name
claude Nov 23, 2026
50e69e7
Tile maps: TMXTilesetGroup is TilesetGroup; the last shared code out …
claude Nov 23, 2026
2c5d837
Tile maps: TMXTileMap is TileMap, loader.getTMX is loader.getTileMap
claude Nov 23, 2026
05e1430
ColorLayer fills its own rectangle when it has a size; LDtk levels us…
claude Nov 23, 2026
a4fe81f
Tests: a ColorLayer fills exactly its rectangle, whatever its positio…
claude Nov 23, 2026
9e26af5
LDtk: an entity with no class is a Container holding its tile's sprite
claude Nov 23, 2026
a2db2bf
LDtk: a repeated tile is drawn as a pattern of the renderer's
claude Nov 23, 2026
c4a0195
Review: registry types, a kinematic entity box, scrolling properties,…
claude Nov 23, 2026
d5ab20d
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 24, 2026
75f925a
Fix Tiled group layers holding any layer, and non-repeating image layers
claude Nov 24, 2026
bd457f6
Merge remote-tracking branch 'origin/master' into claude/hopeful-hypa…
claude Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/melonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
- Tiled: a frame drawn right after a level loaded could show its layers back to front
- Tiled: a `renderMode` property on a tile layer was ignored
- Tiled: each level load leaked a viewport-resize handler
- Tiled: a map with an object layer, an image layer or another group inside a group layer failed to load
- Tiled: the layers of a group of three or more were drawn over the map layers that follow the group; a layer after a group now takes the depth that follows the group's last layer
- Tiled: a group layer's tint is applied to the tile layers inside it
- `ImageLayer`: a layer that does not repeat on an axis smeared its edge pixels across the view on WebGL, and a picture larger than the view was cut off as the camera moved over it

## [20.17.0] (melonJS 2) - _2026-11-22_

Expand Down
26 changes: 19 additions & 7 deletions packages/melonjs/skills/melonjs-tilemaps/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ option and resolve the same value they return — so `if (level.next())` becomes
`if (await level.next({ async: true }))`. Running out of levels reports `false`
either way rather than throwing. `level.getCurrentLevelId()` and
`level.levelCount()` round out the namespace. `flatten: false` wraps each Tiled
object group in its own `Container` named after the group.
object layer and group layer in its own `Container` named after it.

## Spawning entities from Tiled objects

Expand Down Expand Up @@ -371,10 +371,18 @@ board.getTile(pointer.x, pointer.y); // still the tile under the pointer

The other layers follow their offset in Tiled too: an image layer is placed by
it, an object layer's objects are created that far from where they were drawn
(collision shapes with them), and a group layer's offset moves the tile layers
inside it, on top of their own. A group can only hold tile layers: with an
object layer, an image layer or another group inside a group, the map fails
to load.
(collision shapes with them), and a group layer's offset moves the layers
inside it, on top of their own.

A group layer holds layers of any kind: tile layers, object layers, image
layers and other groups (object layers, image layers and nested groups since
20.18). As in Tiled, the group gives the layers inside it its offset, its
opacity, its parallax factor, its blend mode, and its tint where a layer has
none of its own. Every layer takes a depth (`pos.z`) of its own in Tiled's
order, the ones inside a group included, so the layer that follows a group
draws over everything in the group. With `flatten: false`, a group is a
`Container` named after it, holding its tile and image layers, and a
container for each object layer or group inside it.

The map's own custom properties (Map → Map Properties in Tiled) are set on the
map object, which `level.getCurrentLevel()` returns once it is loaded: a
Expand Down Expand Up @@ -568,7 +576,9 @@ the point it belongs with, such as `door.pos.y - dust.pos.y`.
## Image layers

`ImageLayer` gives parallax backgrounds with a ratio per axis, set in Tiled or in
code. Repeat behaviour matches Tiled's.
code. Repeat behaviour matches Tiled's: `repeat` (the default in code),
`repeat-x`, `repeat-y`, or `no-repeat` for a picture drawn once, where the
layer is.

## Compressed maps need a plugin

Expand Down Expand Up @@ -962,7 +972,9 @@ layer into the offscreen-bake path instead.
| 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 |
| a tile layer given an offset in Tiled (a roof nudged up, a shadow shifted) is drawn where the others are, or the objects of an object layer with an offset are not where Tiled shows them | before 20.17 only image layers followed their offset; tile layers (and their `pos`), object layers and group layers ignored it: update |
| after updating to 20.17 a tile layer, or the objects of an object layer, sit away from where they did | the layer (or the group it is in) has an offset in Tiled that was ignored until then, and now moves it as in the editor: clear the layer's Offset in Tiled if it was not meant |
| the map fails to load with a group layer in it | the group holds an object layer, an image layer or another group: a group can only hold tile layers. Move those layers out of the group |
| the map fails to load with a group layer in it (`Cannot read properties of undefined (reading 'length')`) | before 20.18 a group could only hold tile layers: an object layer, an image layer or another group inside it broke the load. Update, or move those layers out of the group |
| a layer of the map is hidden under the layers of the group before it | before 20.18 a group of three or more layers took depths the next layers of the map took too: update. Layers after a group now have a higher `pos.z` than they had |
| an image layer set not to repeat fills the view with streaks of its edge colors on WebGL, or a backdrop larger than the screen is cut off as the camera moves | before 20.18 an axis that does not repeat was drawn over the view's size, not the picture's: update |
| a map smaller than the screen (centred by `level.load`) had the tops of its tall tiles cut on WebGL or WebGPU | before 20.17 a layer read the camera's view as if it stood at the world's origin, and so did a layer in a container the game had moved: update |
| the tops of tall tiles vanish when the map itself scrolls out of view | before 20.17 a layer was skipped once its grid left the view, though tiles larger than a cell (or moved by a `tileoffset`) still reached in: update |
| an orthogonal layer warns `tiles larger than the grid, of more than one tileset in a layer` | tiles larger than a cell overlap, and the shader path keeps their order within one tileset: put each tileset's large tiles on a layer of their own (trees apart from the ground they stand on) |
Expand Down
195 changes: 152 additions & 43 deletions packages/melonjs/src/level/tiled/TMXGroup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { clamp } from "../../math/math.ts";
import { setLayerScrolling } from "../tilemap/layer.js";
import { readImageLayer } from "./TMXImageLayer.js";
import TMXLayer from "./TMXLayer.js";
import TMXObject from "./TMXObject.js";
import {
Expand All @@ -10,13 +11,23 @@ import {
} from "./TMXUtils.js";

/**
* object group definition as defined in Tiled.
* An object layer or a group layer of a Tiled map: the objects of the first,
* and for the second the layers it holds, each read as what it is: tile
* layers, image layers, object layers and other groups. A group gives the
* layers inside it its offset, its opacity, its tint, its blend mode and its
* parallax factor, on top of their own, as in Tiled.
* (group definition is translated into the virtual `app.world` using `me.Container`)
* @ignore
* @internal
*/
export default class TMXGroup {
constructor(map, data, z) {
/**
* @param {object} map - the map
* @param {object} data - the layer, as Tiled saves it
* @param {number} z - the layer's depth: its objects', or its first layer's
* @param {TMXGroup} [parent] - the group layer this one is in
*/
constructor(map, data, z, parent) {
/**
* group name
* @type {string}
Expand All @@ -36,10 +47,10 @@ export default class TMXGroup {
this.height = data.height || 0;

/**
* tint color
* tint color: the layer's own, or else the one of the group it is in
* @type {string}
*/
this.tintcolor = data.tintcolor;
this.tintcolor = data.tintcolor ?? parent?.tintcolor;

/**
* the group class
Expand All @@ -54,8 +65,10 @@ export default class TMXGroup {
this.z = z;

/**
* group objects list definition
* @see {@link TMXObject}
* what the layer holds, in Tiled's order: the objects of an object
* layer ({@link TMXObject}), and for a group layer its tile layers
* and image layers, built, and a `TMXGroup` for each object layer or
* group inside it
* @type {object[]}
*/
this.objects = [];
Expand All @@ -64,14 +77,18 @@ export default class TMXGroup {
this.opacity = visible === true ? clamp(+data.opacity || 1.0, 0.0, 1.0) : 0;

/**
* group blend mode (Tiled 1.12+)
* group blend mode (Tiled 1.12+): the layer's own, or else the one
* of the group it is in
* @type {string}
*/
this.blendMode = tiledBlendMode(data.mode);
if (this.blendMode === "normal" && parent !== undefined) {
this.blendMode = parent.blendMode;
}

/**
* the layer's horizontal offset in Tiled, in pixels: an object layer
* moves its objects by it, a group layer the tile layers inside it
* moves its objects by it, a group layer the layers inside it
* @type {number}
*/
this.offsetx = +data.offsetx || 0;
Expand All @@ -82,9 +99,28 @@ export default class TMXGroup {
*/
this.offsety = +data.offsety || 0;

/**
* how far the layer is moved in all, across and down: its own
* offset and those of the groups it is in
* @type {number}
*/
this.shiftx = this.offsetx + (parent?.shiftx ?? 0);
this.shifty = this.offsety + (parent?.shifty ?? 0);

/**
* the layer's parallax factor, across and down: its own, times
* those of the groups it is in
* @type {number}
*/
this.factorx = tiledParallaxFactor(data.parallaxx) * (parent?.factorx ?? 1);
this.factory = tiledParallaxFactor(data.parallaxy) * (parent?.factory ?? 1);

// check if we have any user-defined properties
applyTMXProperties(this, data);

// the depth of the next layer read: each takes one, in Tiled's order
let next = z;

// parse all child objects/layers
if (data.objects) {
const objects = data.objects;
Expand All @@ -93,50 +129,123 @@ export default class TMXGroup {
const object = new TMXObject(map, objects[i], z);
// Moved on the screen, so once the object stands where its
// map puts it (an isometric map projects it)
object.x += this.offsetx;
object.y += this.offsety;
object.x += this.shiftx;
object.y += this.shifty;
this.objects.push(object);
}
next = z + 1;
}

if (data.layers) {
const layers = data.layers;
for (let i = 0, len = layers.length; i < len; i++) {
const layer = new TMXLayer(
map,
layers[i],
map.tilewidth,
map.tileheight,
map.orientation,
map.tilesets,
z,
);
z++;
// the group's offset, on top of the layer's own
layer.pos.x += this.offsetx;
layer.pos.y += this.offsety;
// and its parallax factor, times the layer's own (Tiled's
// factor, or the layer's `ratio` property); the origin
// follows, unless the layer gave its own
const scrolling = tiledParallax(
map,
tiledParallaxFactor(data.parallaxx) * layer.ratio.x,
tiledParallaxFactor(data.parallaxy) * layer.ratio.y,
);
setLayerScrolling(
layer,
layer._parallaxOriginGiven === true
? { ratio: scrolling.ratio }
: scrolling,
);
// set a renderer
layer.setRenderer(map.getRenderer());
// resize container accordingly
this.width = Math.max(this.width, layer.width);
this.height = Math.max(this.height, layer.height);
this.objects.push(layer);
const child = layers[i];
switch (child.type) {
case "tilelayer":
this.objects.push(this.readTileLayer(map, child, next++));
break;

case "imagelayer":
this.objects.push(this.readImageLayer(map, child, next++));
break;

case "objectgroup":
case "group": {
const group = new TMXGroup(map, child, next, this);
next = group.zEnd;
// resize container accordingly
this.width = Math.max(this.width, group.width);
this.height = Math.max(this.height, group.height);
this.objects.push(group);
break;
}

default:
break;
}
}
}

/**
* the depth that follows the layer: past its last layer's, for a
* group layer
* @type {number}
*/
this.zEnd = Math.max(next, z + 1);
}

/**
* a tile layer of the group, with what the group gives it
* @param {object} map - the map
* @param {object} data - the tile layer, as Tiled saves it
* @param {number} z - its depth
* @returns {TMXLayer} the layer
* @ignore
*/
readTileLayer(map, data, z) {
const layer = new TMXLayer(
map,
data,
map.tilewidth,
map.tileheight,
map.orientation,
map.tilesets,
z,
);
// the group's offset, on top of the layer's own
layer.pos.x += this.shiftx;
layer.pos.y += this.shifty;
// its parallax factor, times the layer's own (Tiled's factor, or
// the layer's `ratio` property); the origin follows, unless the
// layer gave its own
const scrolling = tiledParallax(
map,
this.factorx * layer.ratio.x,
this.factory * layer.ratio.y,
);
setLayerScrolling(
layer,
layer._parallaxOriginGiven === true
? { ratio: scrolling.ratio }
: scrolling,
);
// and its tint, when the layer has none of its own
if (
typeof data.tintcolor !== "string" &&
typeof this.tintcolor === "string"
) {
layer.tint.parseHex(this.tintcolor, true);
}
// set a renderer
layer.setRenderer(map.getRenderer());
// resize container accordingly
this.width = Math.max(this.width, layer.width);
this.height = Math.max(this.height, layer.height);
return layer;
}

/**
* an image layer of the group, with what the group gives it
* @param {object} map - the map
* @param {object} data - the image layer, as Tiled saves it
* @param {number} z - its depth
* @returns {object} the layer
* @ignore
*/
readImageLayer(map, data, z) {
// (a copy: the map's data is left as it is, to be read again)
return readImageLayer(
map,
{
...data,
offsetx: +(data.offsetx ?? data.x ?? 0) + this.shiftx,
offsety: +(data.offsety ?? data.y ?? 0) + this.shifty,
parallaxx: this.factorx * tiledParallaxFactor(data.parallaxx),
parallaxy: this.factory * tiledParallaxFactor(data.parallaxy),
tintcolor: data.tintcolor ?? this.tintcolor,
},
z,
);
}

/**
Expand Down
Loading
Loading