Skip to content
Minh Ngo edited this page Jan 10, 2015 · 39 revisions

A map is returned after using the Loader to load a tmx file. The map contains all the data required for drawing.

##Public ###Data Map.name (default: ")
The name of the map.

Map.width
The width of the map in tiles.

Map.height
The height of the map in tiles.

Map.tilewidth
The width of a tile "cell". Note that tilesets may have different tile dimensions.

Map.tileheight
The height of a tile "cell". Note that tilesets may have different tile dimensions.

Map.orientation (default: "orthogonal")
The orientation of the map. Can either be "orthogonal", "isometric", or "staggered".

Map.properties (default: {})
The properties of the map set in Tiled.

Map.batch_draw (default: true)
If true then all tile layers will be rendered with sprite batches. Batch drawing should be disabled for maps with animations or tilesets with image collections.

Map.layers (default: {})
This table contains all the layers in the map that are indexed by names.

Map.layerOrder (default: {})
This table contains a list of layers in the order that they are drawn.

Map.tilesets (default: {})
This table contains all the tilesets in the map that are indexed by names.

Map.tiles (default: {})
This table contains all the tiles in the map that are indexed by gid.


###Functions Map (width, height, tilewidth, tileheight, args)
Creates a new empty map and returns it. Most likely you'll want to load a map instead. args is an optional table containing optional arguments. Below are their default values:

args = {
	orientation = 'orthogonal',
	layers      = {},
	tilesets    = {},
	layerOrder  = {},
	tiles       = {},
	properties  = {},
}

Map:newTileSet (tilewidth, tileheight, imageOrTable, firstgid, args)
Create a new TileSet object and return it. The parameters are similarly found in the TileSet constructor.

Map:newTileLayer (args, position)
Create a new TileLayer object and return it. The parameters are similarly found in the TileLayer constructor. An optional number, position, argument can be given to define the new layer's draw order. The default position is at the end of the draw list.

Map:newObjectLayer (args, position)
Create a new ObjectLayer object and return it. The parameters are similarly found in the ObjectLayer constructor. An optional number, position, argument can be given to define the new layer's draw order. The default position is at the end of the draw list.

Map:newImageLayer (image, args, position)
Create a new ImageLayer object and return it. The parameters are similarly found in the ImageLayer constructor. An optional number, position, argument can be given to define the new layer's draw order. The default position is at the end of the draw list.

Map:newCustomLayer (name, position, layer)
Create a new CustomLayer object and return it. A CustomLayer is a new table or a provided one via layer. Either way, the table will have the following fields:

CustomLayer = {
	name  = `name` or "Unnamed Layer",
	map   = `map`,
	class = "CustomLayer",
}

An optional number, position, argument can be given to define the new layer's draw order. The default position is at the end of the draw list.

Map:removeLayer (nameOrIndex)
Remove a layer and return it given its name or index in the draw list.

Map:callback (name, ...)
Forwards a callback to all layers inside layerOrder. If a layer has a function with the same name as the callback then it will be triggered. The most common callback is draw but other callbacks can be used to give functionality to custom layers.

Map:draw (x, y)
Draws the map. This is just a shortcut for Map:callback("draw"). x and y are optional positional parameters.

Map:update (dt)
Updates the map. This is just a shortcut for Map:callback("update",dt). This method is used for updating tile animations.

Map:fromIso (x, y)
Turns an isometric location into a world location. The unit length for isometric tiles is always 1 for both width and height.

Map:toIso (x, y)
Turns a world location into an isometric location.

Map:setDrawRange (x, y, x2, y2)
Sets the draw range. Note that the arguments passed to Map:draw have no effects on the draw range. This method forces all layers to be redrawn.

Map:autoDrawRange (cx, cy, scale, padding)
Automatically sets the draw range given the scale and camera center (cx, cy). padding is an optional number for enlarging or shrinking the view. This method is essentially a wrapper for Map:setDrawRange.

map (layer_name)
Calling the map like a function with a layer name as a parameter will return that layer.

Clone this wiki locally