see more...
When you call display.tileMap(), the engine wraps your
display.map into this.map[0] β the first layer.
Calling display.tileFace.addMap(anotherArray) pushes a second
map into this.map[1], a third into this.map[2],
and so on, but none of them are visible yet.
When you call display.tileFace.show(0), the engine clears
tileComm[] completely, rebuilds it from layer 0's map array,
and sets fake.scene = 0 β so ani() only draws
tiles from layer 0 into the fake canvas.
Calling display.tileFace.show(1) does the same thing for
layer 1 β it wipes tileComm[] and rebuilds it entirely from
layer 1's data, replacing layer 0 completely.
This means addMap() is not a layering system β it is a
map switching system. Think of it like levels or rooms:
layer 0 is the grassland level, layer 1 is the dungeon level, layer 2 is
the snow level β calling show(n) swaps the entire world to
that map, the same way display.scene = n swaps which
Components are active.
This makes it perfect for level progression, room transitions, and
alternate map states β the same tile templates are shared across all
layers, so a tile ID of 2 means the same Component in every map.
display.tile = [
new Component(64, 64, "green", 0, 0), // tile 1 = grass
new Component(64, 64, "#333", 0, 0), // tile 2 = dungeon floor
new Component(64, 64, "white", 0, 0), // tile 3 = snow
];
// Layer 0 β grassland level
display.map = [
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 1],
[1, 1, 1, 1, 1],
];
display.tileMap();
display.tileFace.show(0); // display layer 0 β grassland active
// Layer 1 β dungeon level
display.tileFace.addMap([
[2, 2, 2, 2, 2],
[2, 0, 0, 0, 2],
[2, 2, 2, 2, 2],
]);
// Layer 2 β snow level
display.tileFace.addMap([
[3, 3, 0, 3, 3],
[3, 0, 0, 0, 3],
[3, 3, 3, 3, 3],
]);
// Switch to dungeon when player enters a door
function update() {
if (player.crashWith(dungeonDoor)) {
display.tileFace.show(1); // wipes layer 0, switches to dungeon
fake.refresh();
}
if (player.crashWith(snowDoor)) {
display.tileFace.show(2); // switches to snow level
fake.refresh();
}
}
π‘ show(layer) and display.scene follow the
same design philosophy β one switches the active tilemap, the other
switches the active Components. Use them together for complete level
transitions.
| Method | Parameters | What it actually does |
display.tileMap() | β | Creates TileMap β stores display.map as layer 0 |
tileFace.addMap(map2d) | 2D array | Register a new map as the next layer number |
tileFace.show(layer) | layer number | Wipe tileComm[], rebuild from that layer, set fake.scene β switches the active map |
tileFace.add(id,tx,ty,layer) | tileId, gridX, gridY, layer | Edit a tile in any layer's stored data |
tileFace.remove(tx,ty,layer) | gridX, gridY, layer | Remove a tile from any layer's stored data |