Skip to content

🗺️ TILED#

Tiled is a free and open-source map editor used for creating 2D maps. This module allows you to load and render maps created with Tiled.

Note

Currently, ANTIRUINS can only display around 500 sprites at 60fps. I suggest you export all the "static" objects as a single texture and user it in conjuction with renderObjects

local MAP = {
    tileSize    = 16,                       -- size of the tiles in the map
    scale       = 1,                        -- scale at which the map will be rendered
    width       = tileSize * map.width,     -- calculated from the loaded map.
    height      = tileSize * map.height,    -- calculated from the loaded map.
    layers      = {}
    colliders   = {}
}

local LAYER = {
    objects     = {}, -- object data
    drawables   = {}, -- drawable information {gid, x, y, flipX, flipY}
    color       = {1,1,1,1},
    visible     = true,
    name        = "layerName",
}

-- This is the tabled used for each objects in objects layers.
local OBJECTS = {
    x           = 0,
    y           = 0,
    ox,         = 0,            -- orignal x
    oy          = 0,            -- orignal y
    w           = 0,
    h           = 0,
    name        = "objectName",
    type        = "objectType", -- equivalent to class in Tiled
    gid         = 0,            -- sprite id
    visible     = true,
    properties  = {},
    spritesheet = nil,
    color       = {1,1,1,1},
    scale       = 1
}

Loading Maps#

function tiled2.load(file, spritesheet)
Loads a Tiled map from a file and an optional spritesheet.
Returns a map object.

Rendering#

function tiled2:render(layerToRender)
Renders the specified layer. If no layer is specified, renders all layers.

function tiled2:renderObjects()
Renders all objects in the map.

function tiled2:createBatch()
Creates a batch for optimized rendering.

function tiled2:renderBatch(x, y)
Renders the batch at the specified position.

Layers#

function tiled2:getLayer(name)
Returns the layer with the specified name.

Objects#

function tiled2:getObject(name)
Returns the object with the specified name.

function tiled2:getObjects(class)
Returns all objects of the specified class. If no class is specified, returns all objects.

function tiled2:addObject(obj, layer)
Adds an object to the specified layer. If no layer is specified, adds to the first layer.

function tiled2:removeObject(name)
Removes the object with the specified name.

Utilities#

function tiled2:free()
Frees the resources used by the map.

function tiled2:getTile(gid)
Returns the real GID of a tile, considering flip flags.

Note

This is required to get the proper tiles ID if your flipped some sprites in Tiled. is flipped.

function tiled2:getFlip(gid)
Returns the flip flags and real GID of a tile.