melonJS
    Preparing search index...

    Class TileMap

    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 Fusion map.json. It is read in the words of either editor, and left as it is:

    Tiled Sprite Fusion
    the map's size, in tiles width, height mapWidth, mapHeight
    the size of a tile tilewidth, tileheight tileSize
    a layer's tiles data: the gid of every cell tiles: a list of { id, x, y, attributes }
    custom values properties attributes, a plain object, kept as written
    a solid tile layer a collider property set to true the layer's collider field
    the tilesets tilesets none named: the spritesheet image
    the order of the layers the bottom one first the top one first

    attributes is read wherever properties is (the map, a layer, an object, a tile of a tileset, a tile of a tiles list), in a map of either form.

    Index
    • Parameters

      • levelId: string

        name of the map

      • data: object

        the map's description: a Tiled map in JSON format, or a Sprite Fusion map.json

      Returns TileMap

      // 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);
    backgroundcolor: any
    bounds: Bounds
    class: string

    The map class.

    cols: number

    width of the tilemap in tiles

    format: string

    level format discriminator used by the level director's dispatch

    hexsidelength: number
    infinite: number

    is the map an infinite map

    0
    
    initialized: boolean
    isEditor: boolean
    layers: any[]
    name: string

    name of the tilemap

    nextobjectid: number
    objectGroups: any[]
    orientation: string

    the map orientation type. melonJS supports “orthogonal”, “isometric”, “staggered”, “hexagonal” and “oblique”.

    “orthogonal”
    
    renderorder: string

    the order in which tiles on orthogonal tile layers are rendered. (valid values are "left-down", "left-up", "right-down", "right-up")

    "right-down"
    
    rows: number

    height of the tilemap in tiles

    skewx: number

    horizontal skew in pixels per tile row (oblique maps, since Tiled 1.12)

    0
    
    skewy: number

    vertical skew in pixels per tile column (oblique maps, since Tiled 1.12)

    0
    
    staggeraxis: any
    staggerindex: any
    tiledversion: string

    The Tiled version used to save the file (since Tiled 1.0.1).

    tileheight: number

    Tile height

    tilesets: TilesetGroup | null | undefined
    tilewidth: number

    Tile width

    version: string

    the TMX format version

    • add all the map layers and objects to the given container. note : this will not automatically update the camera viewport

      Parameters

      • container: Container

        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

      Returns void

      // create a new level object based on the TMX JSON object
      let level = new me.TileMap(levelId, me.loader.getTileMap(levelId));
      // add the level to the game world container
      level.addTo(app.world, true, true);
    • 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.

      Parameters

      • 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

      Returns Renderable[]

      Array of Objects