Module map

Map object

Functions

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

Tables

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


Functions

Map:init (path, plugins)
Instance a new map

Parameters:

  • path Path to the map file
  • plugins A list of plugins to load

Returns:

    nil
Map:loadPlugins (plugins)
Load plugins

Parameters:

  • plugins A list of plugins to load

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:setLayer (layer, path)
Create Layers

Parameters:

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

Returns:

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

Parameters:

  • layer The Tile Layer

Returns:

    nil
Map:setObjectData (layer)
Add Objects to Layer

Parameters:

  • layer The Object Layer

Returns:

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

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:setObjectSpriteBatches (layer)
Batch Tiles in Object Layer for improved draw speed

Parameters:

  • layer The Object Layer

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: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:convertToCustomLayer (index)
Convert another Layer into a Custom Layer

Parameters:

  • index Index or name of Layer to convert

Returns:

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

Parameters:

  • index Index or name of Layer to convert

Returns:

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

Parameters:

  • dt Delta Time

Returns:

    nil
Map:draw ()
Draw every Layer

Returns:

    nil
Map:drawLayer (layer)
Draw an individual Layer

Parameters:

  • layer The Layer to draw

Returns:

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

Parameters:

  • layer The Tile Layer to draw

Returns:

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

Parameters:

  • layer The Object Layer to draw

Returns:

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

Parameters:

  • layer The Image Layer to draw

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:setFlippedGID (gid)
Create flipped or rotated Tiles based on bitop flags

Parameters:

  • gid The flagged Global ID

Returns:

    table Flipped Tile
Map:getLayerProperties (layer)
Get custom properties from Layer

Parameters:

  • layer The Layer

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: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:convertIsometricToScreen (x, y)
Project isometric position to orthoganal position

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 pixels)
  2. number The Y axis location of the point (in pixels)
Map:convertScreenToIsometric (x, y)
Project orthoganal position to isometric position

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 pixels)
  2. number The Y axis location of the point (in pixels)
Map:convertTileToScreen (x, y)
Convert orthoganal 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:convertScreenToTile (x, y)
Convert orthoganal 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:convertIsometricTileToScreen (x, y)
Convert isometric 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:convertScreenToIsometricTile (x, y)
Convert isometric 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:convertStaggeredTileToScreen (x, y)
Convert staggered isometric 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:convertScreenToStaggeredTile (x, y)
Convert staggered isometric 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)

Tables

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

See also:

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

See also:

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

See also:

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

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:

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:

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:

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
    
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:

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:

generated by LDoc 1.4.3 Last updated 2015-10-12 08:32:34