Module cartographer

Tiled map loading and drawing library for LÖVE.

Functions

load (path) Loads a Tiled map from an exported Lua file.

Layer

Layer.base:gridToPixel (x, y) Converts grid coordinates to pixel coordinates for this layer.
Layer.base:pixelToGrid (x, y) Converts pixel coordinates for this layer to grid coordinates.

SpriteLayer

Layer.spritelayer:update (dt) Updates animations on the layer.
Layer.spritelayer:draw () Draws the layer.

TileLayer

Layer.tilelayer:getGridBounds () Gets the bounds of the layer (in tiles).
Layer.tilelayer:getPixelBounds () Gets the bounds of the layer (in pixels).
Layer.tilelayer:getTileAtGridPosition (x, y) Gets the tile at the given grid position.
Layer.tilelayer:setTileAtGridPosition (x, y, gid) Sets the tile at the given grid position.
Layer.tilelayer:getTileAtPixelPosition (x, y) Gets the tile at the given pixel position.
Layer.tilelayer:setTileAtPixelPosition (x, y, gid) Sets the tile at the given pixel position.
Layer.tilelayer:getTiles () Returns an iterator over all the tiles in this layer.

ImageLayer

Layer.imagelayer:draw () Draws the layer.

Group

Layer.group:getLayer (...) Gets a child layer by name.
Layer.group:update (dt) Updates animations in all child layers.
Layer.group:draw () Draws the layer.

Map

Map:getTileset (gid) Gets the tileset that has the tile with the given global ID.
Map:getTile (gid) Gets a tile with the given global ID.
Map:getTileType (gid) Gets the type of a tile.
Map:getTileProperty (gid, propertyName) Gets the value of a property of a tile.
Map:setTileProperty (gid, propertyName, propertyValue) Sets the value of a tile property.
Map:getLayer (...) Gets a layer by name.
Map:update (dt) Updates all animations in the map.
Map:drawBackground () Draws the solid color background of the map.
Map:draw () Draws the map.


Functions

load (path)
Loads a Tiled map from an exported Lua file.

Parameters:

  • path string the path to the Lua file

Returns:

    the loaded Map

Layer

The base class for all layers.
Layer.base:gridToPixel (x, y)
Converts grid coordinates to pixel coordinates for this layer.

Parameters:

  • x number the column to get the pixel coordinates of
  • y number the row to get the pixel coordinates of

Returns:

  1. the horizontal position of the grid cell in pixels
  2. the vertical position of the grid cell in pixels
Layer.base:pixelToGrid (x, y)
Converts pixel coordinates for this layer to grid coordinates.

Parameters:

  • x number the horizontal position to get the grid cell at
  • y number the vertical position to get the grid cell at

Returns:

  1. the column of the grid cell
  2. the row of the grid cell

SpriteLayer

Parent class for tile layers and object layers.
Layer.spritelayer:update (dt)
Updates animations on the layer.

Parameters:

  • dt number the time elapsed since the last frame (in seconds)
Layer.spritelayer:draw ()
Draws the layer.

TileLayer

A layer that contains tiles placed on a grid.

Inherits from SpriteLayer.

Layer.tilelayer:getGridBounds ()
Gets the bounds of the layer (in tiles).

Returns:

  1. the left bound of the layer
  2. the top bound of the layer
  3. the right bound of the layer
  4. the bottom bound of the layer
Layer.tilelayer:getPixelBounds ()
Gets the bounds of the layer (in pixels).

Returns:

  1. the left bound of the layer
  2. the top bound of the layer
  3. the right bound of the layer
  4. the bottom bound of the layer
Layer.tilelayer:getTileAtGridPosition (x, y)
Gets the tile at the given grid position.

Parameters:

  • x number the column to get the tile at
  • y number the row to get the tile at

Returns:

    the global ID of the tile at the given grid position, or false if the tile is empty
Layer.tilelayer:setTileAtGridPosition (x, y, gid)
Sets the tile at the given grid position.

Parameters:

  • x number the column to set the tile at
  • y number the row to set the tile at
  • gid number the global ID to set the tile to
Layer.tilelayer:getTileAtPixelPosition (x, y)
Gets the tile at the given pixel position.

Parameters:

  • x number the horizontal position to get the tile at
  • y number the vertical position to get the tile at

Returns:

    the global ID of the tile at the given pixel position, or false if the tile is empty
Layer.tilelayer:setTileAtPixelPosition (x, y, gid)
Sets the tile at the given pixel position.

Parameters:

  • x number the horizontal position to set the tile at
  • y number the vertical position to set the tile at
  • gid number the global ID to set the tile to
Layer.tilelayer:getTiles ()
Returns an iterator over all the tiles in this layer.

Returns:

    an iterator that returns that following values:

    • the index of the tile
    • the global ID of the tile
    • the x position of the tile (in grid cells)
    • the y position of the tile (in grid cells)
    • the x position of the tile (in pixels)
    • the y position of the tile (in pixels)

ImageLayer

A layer that displays a single image.
Layer.imagelayer:draw ()
Draws the layer.

Group

A layer that contains other layers.
Layer.group:getLayer (...)
Gets a child layer by name.

Can get nested layers.

Parameters:

  • ... string the name(s) of the layers to get

Returns:

    the Layer, if it exists
Layer.group:update (dt)
Updates animations in all child layers.

Parameters:

  • dt number the elapsed time since the last frame (in seconds)
Layer.group:draw ()
Draws the layer.

Map

A tiled map.
Map:getTileset (gid)
Gets the tileset that has the tile with the given global ID.

Parameters:

  • gid number the global ID of the tile

Returns:

    the tileset that contains the tile, if it exists
Map:getTile (gid)
Gets a tile with the given global ID.

Parameters:

  • gid number the global ID of the tile

Returns:

    the data table for the tile with the given global ID, if it exists
Map:getTileType (gid)
Gets the type of a tile.

Parameters:

  • gid number the global ID of the tile

Returns:

    the type of the tile with the given global ID, if it exists
Map:getTileProperty (gid, propertyName)
Gets the value of a property of a tile.

Parameters:

  • gid number the global ID of the tile
  • propertyName string the name of the property

Returns:

    the value of the property, if it exists
Map:setTileProperty (gid, propertyName, propertyValue)
Sets the value of a tile property.

Parameters:

  • gid number the global ID of the tile
  • propertyName string the name of the property
  • propertyValue the value to set the property to
Map:getLayer (...)
Gets a layer by name.

Can get nested layers.

Parameters:

  • ... string the name(s) of the layers to get

Returns:

    the Layer, if it exists
Map:update (dt)
Updates all animations in the map.

Parameters:

  • dt number the elapsed time since the last frame
Map:drawBackground ()
Draws the solid color background of the map.
Map:draw ()
Draws the map.
generated by LDoc 1.4.6 Last updated 2020-04-24 01:38:44