Module sti

Simple and fast Tiled map loader and renderer.

Info:

  • Copyright: 2019
  • License: MIT/X11
  • Author: Landon Manning

Functions

Map.drawLayer (layer) Draw an individual Layer
Map:addCustomLayer (name, index) Create a Custom Layer to place userdata in (such as player sprites)
Map:addNewLayerTile (layer, chunk, tile, number, number) Place new tile instance
Map:convertPixelToTile (x, y) Convert pixel location to tile location
Map:convertTileToPixel (x, y) Convert tile location to pixel location
Map:convertToCustomLayer (index) Convert another Layer into a Custom Layer
Map:draw (tx, ty, sx, sy) Draw every Layer
Map:drawImageLayer (layer) Default draw function for Image Layers
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:getLayerTilePosition (layer, tile, x, y) Convert tile location to tile instance location
Map:getObjectProperties (layer, object) Get custom properties from Object
Map:getTileProperties (layer, x, y) Get custom properties from Tile
Map:groupAppendToList (layers, layer) Layers from the group are added to the list
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:setFlippedGID (gid) Create flipped or rotated Tiles based on bitop flags
Map:setLayer (layer, path) Create Layers
Map:setLayerTile (layer, x, y, gid) Change a tile in a layer to another tile
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
STI.__call (map, plugins, ox, oy) Instance a new map.
STI:flush () Flush image cache.

Tables

CustomLayer Custom Layers are used to place userdata such as sprites within the draw order of the map.
ImageLayer
Map.freeBatchSprites A list of no-longer-used batch sprites, indexed by batch
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.drawLayer (layer)
Draw an individual Layer

Parameters:

  • layer The Layer to draw
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:addNewLayerTile (layer, chunk, tile, number, number)
Place new tile instance

Parameters:

  • layer Tile layer
  • chunk Layer chunk
  • tile Tile
  • number Tile location on Y axis (in tiles)
  • number Tile location on Y axis (in tiles)
Map:convertPixelToTile (x, y)
Convert pixel location to tile location

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:convertTileToPixel (x, y)
Convert tile location to pixel location

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

Parameters:

  • index Index or name of Layer to convert

Returns:

    table Custom Layer
Map:draw (tx, ty, sx, sy)
Draw every Layer

Parameters:

  • tx Translate on X
  • ty Translate on Y
  • sx Scale on X
  • sy Scale on Y
Map:drawImageLayer (layer)
Default draw function for Image Layers

Parameters:

  • layer The Image Layer to draw
Map:drawObjectLayer (layer)
Default draw function for Object Layers

Parameters:

  • layer The Object Layer to draw
Map:drawTileLayer (layer)
Default draw function for Tile Layers

Parameters:

  • layer The Tile Layer to draw
Map:getLayerProperties (layer)
Get custom properties from Layer

Parameters:

  • layer The Layer

Returns:

    table List of properties
Map:getLayerTilePosition (layer, tile, x, y)
Convert tile location to tile instance location

Parameters:

  • layer Tile layer
  • tile Tile
  • x Tile location on X axis (in tiles)
  • y Tile location on Y axis (in tiles)

Returns:

  1. number Tile instance location on X axis (in pixels)
  2. number Tile instance location on Y axis (in pixels)
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:groupAppendToList (layers, layer)
Layers from the group are added to the list

Parameters:

  • layers List of layers
  • layer Layer data
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)
Map:loadPlugins (plugins)
Load plugins

Parameters:

  • plugins A list of plugins to load
Map:removeLayer (index)
Remove a Layer from the Layer stack

Parameters:

  • index Index or name of Layer to remove
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)
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
Map:setLayerTile (layer, x, y, gid)
Change a tile in a layer to another 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)
  • gid The gid of the new tile
Map:setObjectCoordinates (layer)
Correct position and orientation of Objects in an Object Layer

Parameters:

  • layer The Object Layer
Map:setObjectData (layer)
Add Objects to Layer

Parameters:

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

Parameters:

  • layer The Object Layer
Map:setSpriteBatches (layer)
Batch Tiles in Tile Layer for improved draw speed

Parameters:

  • layer The Tile Layer
Map:setTileData (layer)
Add Tiles to Tile Layer

Parameters:

  • layer The Tile Layer
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
STI.__call (map, plugins, ox, oy)
Instance a new map.

Parameters:

  • map Path to the map file or the map table itself
  • 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:

    table The loaded Map
STI:flush ()
Flush image cache.

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 = lg.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
    		lg.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.freeBatchSprites
A list of no-longer-used batch sprites, indexed by batch
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 tileWo 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.6 Last updated 2020-04-16 17:17:47