Module map

Map object

Functions

Map:addCustomLayer (name, index) Create a Custom Layer to place userdata in (such as player sprites)
Map:convertScreenToWorld (x, y) Convert screen space to tile space
Map:convertToCustomLayer (index) Convert another Layer into a Custom Layer
Map:convertWorldToScreen (x, y) Convert tile space to screen space
Map:draw () Draw every Layer
Map:drawImageLayer (layer) Default draw function for Image Layers
Map:drawLayer (layer) Draw an individual Layer
Map:drawObjectLayer (layer) Default draw function for Object Layers
Map:drawTileLayer (layer) Default draw function for Tile Layers
Map:getLayerProperties (layer) Get custom properties from Layer
Map:getObjectProperties (layer, object) Get custom properties from Object
Map:getTileProperties (layer, x, y) Get custom properties from Tile
Map:init (path, plugins, ox, oy) Instance a new map
Map:loadPlugins (plugins) Load plugins
Map:removeLayer (index) Remove a Layer from the Layer stack
Map:resize (w, h) Resize the drawable area of the Map
Map:setDrawRange (tx, ty, w, h) Only draw what is visible on screen for improved draw speed
Map:setFlippedGID (gid) Create flipped or rotated Tiles based on bitop flags
Map:setLayer (layer, path) Create Layers
Map:setObjectCoordinates (layer) Correct position and orientation of Objects in an Object Layer
Map:setObjectData (layer) Add Objects to Layer
Map:setObjectSpriteBatches (layer) Batch Tiles in Object Layer for improved draw speed
Map:setSpriteBatches (layer) Batch Tiles in Tile Layer for improved draw speed
Map:setTileData (layer) Add Tiles to Tile Layer
Map:setTiles (index, tileset, gid) Create Tiles
Map:swapTile (instance, tile) Swap a tile in a spritebatch
Map:update (dt) Animate Tiles and update every Layer

Tables

CustomLayer Custom Layers are used to place userdata such as sprites within the draw order of the map.
ImageLayer
Map.layers A list of individual layers indexed both by draw order and name
Map.objects A list of individual objects indexed by Global ID
Map.tileInstances A list of tile instances indexed by Global ID
Map.tiles A list of individual tiles indexed by Global ID
Object
ObjectLayer
Tile
TileInstance
TileLayer


Functions

Map:addCustomLayer (name, index)
Create a Custom Layer to place userdata in (such as player sprites)

Parameters:

  • name Name of Custom Layer
  • index Draw order within Layer stack

Returns:

    table Custom Layer
Map:convertScreenToWorld (x, y)
Convert screen space to tile space

Parameters:

  • x The X axis location of the point (in pixels)
  • y The Y axis location of the point (in pixels)

Returns:

  1. number The X axis location of the point (in tiles)
  2. number The Y axis location of the point (in tiles)
Map:convertToCustomLayer (index)
Convert another Layer into a Custom Layer

Parameters:

  • index Index or name of Layer to convert

Returns:

    table Custom Layer
Map:convertWorldToScreen (x, y)
Convert tile space to screen space

Parameters:

  • x The X axis location of the point (in tiles)
  • y The Y axis location of the point (in tiles)

Returns:

  1. number The X axis location of the point (in pixels)
  2. number The Y axis location of the point (in pixels)
Map:draw ()
Draw every Layer

Returns:

    nil
Map:drawImageLayer (layer)
Default draw function for Image Layers

Parameters:

  • layer The Image Layer to draw

Returns:

    nil
Map:drawLayer (layer)
Draw an individual Layer

Parameters:

  • layer The Layer to draw

Returns:

    nil
Map:drawObjectLayer (layer)
Default draw function for Object Layers

Parameters:

  • layer The Object Layer to draw

Returns:

    nil
Map:drawTileLayer (layer)
Default draw function for Tile Layers

Parameters:

  • layer The Tile Layer to draw

Returns:

    nil
Map:getLayerProperties (layer)
Get custom properties from Layer

Parameters:

  • layer The Layer

Returns:

    table List of properties
Map:getObjectProperties (layer, object)
Get custom properties from Object

Parameters:

  • layer The Layer that the Object belongs to
  • object The index or name of the Object

Returns:

    table List of properties
Map:getTileProperties (layer, x, y)
Get custom properties from Tile

Parameters:

  • layer The Layer that the Tile belongs to
  • x The X axis location of the Tile (in tiles)
  • y The Y axis location of the Tile (in tiles)

Returns:

    table List of properties
Map:init (path, plugins, ox, oy)
Instance a new map

Parameters:

  • path Path to the map file
  • plugins A list of plugins to load
  • ox Offset of map on the X axis (in pixels)
  • oy Offset of map on the Y axis (in pixels)

Returns:

    nil
Map:loadPlugins (plugins)
Load plugins

Parameters:

  • plugins A list of plugins to load

Returns:

    nil
Map:removeLayer (index)
Remove a Layer from the Layer stack

Parameters:

  • index Index or name of Layer to convert

Returns:

    nil
Map:resize (w, h)
Resize the drawable area of the Map

Parameters:

  • w The new width of the drawable area (in pixels)
  • h The new Height of the drawable area (in pixels)

Returns:

    nil
Map:setDrawRange (tx, ty, w, h)
Only draw what is visible on screen for improved draw speed

Parameters:

  • tx Translate X axis (in pixels)
  • ty Translate Y axis (in pixels)
  • w Width of screen (in pixels)
  • h Height of screen (in pixels)

Returns:

    nil
Map:setFlippedGID (gid)
Create flipped or rotated Tiles based on bitop flags

Parameters:

  • gid The flagged Global ID

Returns:

    table Flipped Tile
Map:setLayer (layer, path)
Create Layers

Parameters:

  • layer Layer data
  • path (Optional) Path to an Image Layer's image

Returns:

    nil
Map:setObjectCoordinates (layer)
Correct position and orientation of Objects in an Object Layer

Parameters:

  • layer The Object Layer

Returns:

    nil
Map:setObjectData (layer)
Add Objects to Layer

Parameters:

  • layer The Object Layer

Returns:

    nil
Map:setObjectSpriteBatches (layer)
Batch Tiles in Object Layer for improved draw speed

Parameters:

  • layer The Object Layer

Returns:

    nil
Map:setSpriteBatches (layer)
Batch Tiles in Tile Layer for improved draw speed

Parameters:

  • layer The Tile Layer

Returns:

    nil
Map:setTileData (layer)
Add Tiles to Tile Layer

Parameters:

  • layer The Tile Layer

Returns:

    nil
Map:setTiles (index, tileset, gid)
Create Tiles

Parameters:

  • index Index of the Tileset
  • tileset Tileset data
  • gid First Global ID in Tileset

Returns:

    number Next Tileset's first Global ID
Map:swapTile (instance, tile)
Swap a tile in a spritebatch

Parameters:

  • instance The current Instance object we want to replace
  • tile The Tile object we want to use

Returns:

    none
Map:update (dt)
Animate Tiles and update every Layer

Parameters:

  • dt Delta Time

Returns:

    nil

Tables

CustomLayer
Custom Layers are used to place userdata such as sprites within the draw order of the map.

Fields:

  • name The name of the layer
  • x Position on the X axis (in pixels)
  • y Position on the Y axis (in pixels)
  • visible Toggle if layer is visible or hidden
  • opacity Opacity of layer
  • properties Custom properties
  • update Update function
  • draw Draw function

See also:

Usage:

    	-- Create a Custom Layer
    	local spriteLayer = map:addCustomLayer("Sprite Layer", 3)
    
    	-- Add data to Custom Layer
    	spriteLayer.sprites = {
    		player = {
    			image = love.graphics.newImage("assets/sprites/player.png"),
    			x = 64,
    			y = 64,
    			r = 0,
    		}
    	}
    
    	-- Update callback for Custom Layer
    	function spriteLayer:update(dt)
    		for _, sprite in pairs(self.sprites) do
    			sprite.r = sprite.r + math.rad(90 * dt)
    		end
    	end
    
    	-- Draw callback for Custom Layer
    	function spriteLayer:draw()
    		for _, sprite in pairs(self.sprites) do
    			local x = math.floor(sprite.x)
    			local y = math.floor(sprite.y)
    			local r = sprite.r
    			love.graphics.draw(sprite.image, x, y, r)
    		end
    	end
ImageLayer

Fields:

  • name The name of the layer
  • x Position on the X axis (in pixels)
  • y Position on the Y axis (in pixels)
  • visible Toggle if layer is visible or hidden
  • opacity Opacity of layer
  • properties Custom properties
  • image Image to be drawn
  • update Update function
  • draw Draw function

See also:

Map.layers
A list of individual layers indexed both by draw order and name

See also:

Map.objects
A list of individual objects indexed by Global ID

See also:

Map.tileInstances
A list of tile instances indexed by Global ID

See also:

Map.tiles
A list of individual tiles indexed by Global ID

See also:

Object

Fields:

  • id Global ID
  • name Name of object (non-unique)
  • shape Shape of object
  • x Position of object on X axis (in pixels)
  • y Position of object on Y axis (in pixels)
  • width Width of object (in pixels)
  • height Heigh tof object (in pixels)
  • rotation Rotation of object (in radians)
  • visible Toggle if object is visible or hidden
  • properties Custom properties
  • ellipse List of verticies of specific shape
  • rectangle List of verticies of specific shape
  • polygon List of verticies of specific shape
  • polyline List of verticies of specific shape

See also:

ObjectLayer

Fields:

  • name The name of the layer
  • x Position on the X axis (in pixels)
  • y Position on the Y axis (in pixels)
  • visible Toggle if layer is visible or hidden
  • opacity Opacity of layer
  • properties Custom properties
  • objects List of objects indexed by draw order
  • update Update function
  • draw Draw function

See also:

Tile

Fields:

  • id Local ID within Tileset
  • gid Global ID
  • tileset Tileset ID
  • quad Quad object
  • properties Custom properties
  • terrain Terrain data
  • animation Animation data
  • frame Current animation frame
  • time Time spent on current animation frame
  • width Width of tile
  • height Height of tile
  • sx Scale value on the X axis
  • sy Scale value on the Y axis
  • r Rotation of tile (in radians)
  • offset Offset drawing position
    • x Offset value on the X axis
    • y Offset value on the Y axis

See also:

TileInstance

Fields:

  • batch Spritebatch the Tile Instance belongs to
  • id ID within the spritebatch
  • gid Global ID
  • x Position on the X axis (in pixels)
  • y Position on the Y axis (in pixels)

See also:

TileLayer

Fields:

  • name The name of the layer
  • x Position on the X axis (in pixels)
  • y Position on the Y axis (in pixels)
  • width Width of layer (in tiles)
  • height Height of layer (in tiles)
  • visible Toggle if layer is visible or hidden
  • opacity Opacity of layer
  • properties Custom properties
  • data A two dimensional table filled with individual tiles indexed by [y][x] (in tiles)
  • update Update function
  • draw Draw function

See also:

generated by LDoc 1.4.3 Last updated 2016-06-09 23:18:58