Tutorial:Advanced Tiled Loader

In this tutorial we will cover the basics of using Kadoba's Advanced Tiled Loader. You'll need the Advanced Tiled Loader (in the AdvTiledLoader directory), a mapfile generated by Tiled, and a texturepack in the appropriate location. Let's start with the love.load function:

function love.load()
  
  loader = require("AdvTiledLoader.Loader")
  loader.path = "maps/" --Change this to wherever your .tmx files are
  map = loader.load("mapfile.tmx") --Change this to the name of your mapfile
  tx = 0
  ty = 0
  scale = 1 -- Adjust zoom with this
  
end

Here we load the ATL and tell it where our maps are. We load the maps and initialize our variables. Moving onto love.draw:

function love.draw()
  local ftx, fty = math.floor(tx), math.floor(ty)
  love.graphics.push()
  love.graphics.scale(scale)
  love.graphics.translate(ftx, fty)
  map:draw()
  love.graphics.pop()
end

In the love.draw function we change tx and ty into integers. This makes for slightly smoother graphics should. We move around the image with love.graphics.translate, and then we call map:draw to actually render it for us.

function love.update(dt)
  if love.keyboard.isDown("up") then ty = ty + 250*dt end
  if love.keyboard.isDown("down") then ty = ty - 250*dt end
  if love.keyboard.isDown("left") then tx = tx + 250*dt end
  if love.keyboard.isDown("right") then tx = tx - 250*dt end
end

Here we listen for a keypress and then adjust the translate variables, tx and ty appropriately.

More information can be found on Kadoba's original post here. More advanced samples are included with the loader itself.

See Also

Tile-based Scrolling
Efficient Tile-based Scrolling



Other languages