name of the map
the map's description: a Tiled map in JSON format, or a Sprite Fusion map.json
// create a new level object based on the map's description
let level = new me.TileMap(levelId, me.loader.getTileMap(levelId));
// add the level to the game world container
level.addTo(app.world, true);
// a map written by hand, in the shorter words: two tiles, one of them lava
const map = new TileMap("tiny", {
tileSize: 16,
mapWidth: 4,
mapHeight: 2,
layers: [{
name: "ground",
collider: true,
tiles: [
{ id: 0, x: 0, y: 1 },
{ id: 1, x: 1, y: 1, attributes: { type: "lava", damage: 25 } },
],
}],
}); // drawn from the image loaded as "spritesheet"
map.addTo(app.world, true);
The map class.
width of the tilemap in tiles
level format discriminator used by the level director's dispatch
is the map an infinite map
name of the tilemap
the map orientation type. melonJS supports “orthogonal”, “isometric”, “staggered”, “hexagonal” and “oblique”.
the order in which tiles on orthogonal tile layers are rendered. (valid values are "left-down", "left-up", "right-down", "right-up")
height of the tilemap in tiles
horizontal skew in pixels per tile row (oblique maps, since Tiled 1.12)
vertical skew in pixels per tile column (oblique maps, since Tiled 1.12)
The Tiled version used to save the file (since Tiled 1.0.1).
Tile height
Tile width
the TMX format version
the map's height in pixels: its bounds' height (see TileMap#getBounds)
the map's width in pixels: its bounds' width (see TileMap#getBounds)
add all the map layers and objects to the given container. note : this will not automatically update the camera viewport
target container
Optionalflatten: boolean
if true, flatten all objects into the given container, else a me.Container object will be created for each corresponding groups
OptionalsetViewportBounds: boolean
if true, set the viewport bounds to the map size, this should be set to true especially if adding a level to the game world container.
Optionalobjects: boolean | Function
build the map's objects: all of them, none, or the ones a function (settings) => boolean says. See level.load
destroy function, clean all allocated objects
return the map bounding rect: the area its tiles are drawn in. On an infinite map, the map's own area grown to every painted tile, which can start left of or above 0
Return an Array of instantiated objects, based on the map object definition. Objects are created using the Tiled object factory registry, which dispatches to the appropriate factory based on the object's class, name, or structure. Custom factories can be registered via registerObjectFactory or registerObjectClass.
Optionalflatten: boolean
if true, flatten all objects into the returned array.
when false, a me.Container object will be created for each corresponding groups
Optionalwanted: boolean | Function
the objects to build: all of them, none (false), or the ones a function says, given each object's settings
Array of Objects
A tile map as a level: its layers, its tilesets and the objects it places, read from a map description and added to the world by level.load.
The description is what the loader keeps for a
"tmx","tilemap"or"spritefusion"asset (loader.getTileMap): a Tiled map (Tiled QT +0.7.x format), from XML or JSON, or a Sprite Fusionmap.json. It is read in the words of either editor, and left as it is:width,heightmapWidth,mapHeighttilewidth,tileheighttileSizedata: the gid of every celltiles: a list of{ id, x, y, attributes }propertiesattributes, a plain object, kept as writtencolliderproperty set to truecolliderfieldtilesetsspritesheetimageattributesis read whereverpropertiesis (the map, a layer, an object, a tile of a tileset, a tile of atileslist), in a map of either form.