-
Notifications
You must be signed in to change notification settings - Fork 4
The map class is used to create a drawable map object.
map.new(image,atlas[, tw,th])
or
map(image,atlas[, tw,th])
Returns an empty map object. A map object is a collection of sprite batches. The tilewidth default: quadwidth
and tileheight default: tilewidth or quadheight
arguments are optional. setViewRange must
also be used to draw the map.
map:export([dimension,reverse])
Exports the map data as a 1d (default
) or 2d array. The array has fields width and height for
the map size. If the array is 2d, tile indices can be accessed by array[x][y]
. If reverse
is true
,
the 2d array is accessed by array[y][x]
. Empty tiles have the 0 index. For 1d array, the indices
have row major order.
map:setName(name)
Sets the name of the map. The name is also used when saving.
map:getName()
Returns the name of the map.
map:setImageSource(filename)
Sets the filename (and path) of the image. This MUST be set when using the TMX loader/saver.
map:getImageSource()
Returns the relative path to the image.
map:getAtlas()
Returns the atlas used by the map.
map:getTileSize()
Returns the width and height of each tiles.
map:setTile(tx,ty[,index,angle,flipx,flipy])
Assign an atlas index to a tile. The index parameter accepts a table or number like an atlas. If no index is given, the tile will not be drawn. Assigning an index will reset the angle and flip status or use the optional arguments.
map:getTile(tx,ty)
Get the atlas index of a tile. Returns a number or nil if nothing is assigned.
map:setProperty(tx,ty,v)
Assigns a custom value to the tile coordinates. This is similar to grid:set. Could be useful for tagging additional information to a tile.
map:getProperty(tx,ty)
Returns the custom value assigned to the tile coordinates. This is similar to grid:get
map:setImage(image)
Sets an image for the tile textures.
map:getImage()
Returns the image in use by the map.
map:setFlip(tx,ty,flipx,flipy)
Sets the flip status of a tile. flipx and flipy must be true to flip horizontally and vertically, respectively.
map:getFlip(tx,ty)
Returns the flip status as two values; they are flipx and flipy.
map:setAngle(tx,ty,angle)
Sets the angle in radians of a tile. All tiles have a starting angle of 0.
map:getAngle(tx,ty)
Returns the angle of a tile.
map:setViewRange(x1,y1,x2,y2)
Sets the viewing range of tiles. All sprite batches found in viewing range are drawn. Note that the origin is located on the top left corner of tile (1,1). For example, to draw from tile (1,1) to tile (2,2), do map:setViewRange(1,1,2,2).
map:getViewRange()
Returns the current viewing range ( x1,y1,x2,y2 ).
map:draw([x,y,r,sx,sy,ox,oy,kx,ky])
Draws the map. The arguments are like the ones in love.graphics.draw. The draw origin is by default located at the top left corner of tile (1,1).
map(tx,ty)
Shortcut for map:getTile
The following functions are available when using the TMX loader.
map:getOpacity()
Returns the opacity of the layer.
map:setOpacity(opacity)
Sets the opacity of the layer. It must be value from 0 to 1.
map:getLayerProperties()
Returns the table containing the layer properties where value = table[name]