Search code examples
lualove2d

How to use Tiled Maps/Tileset exported as Lua in Love2d


I have exported my Game world (Tiles + Collision Tiles) from Tiled as a Lua File, How do i integrate this into my Love2d Game and Determine which one is a Walkable path and Which one is not?


Solution

  • If you look in this question (What code do I wrap around Lua code in C++ with LuaBind?) you will find an example of what the lua file looks like. All it is is a file that when run in lua will return a dictionary containing all the data about your game world.

    Assuming your map is called "mymap.lua" you would do this in one of the following ways:

    require("mymap")
    local mymap = love.filesystem.load("mymap.lua")()
    

    Then, to use it, you would do something like:

    -- loads the sprites of the first tileset
    local tileset1 = love.graphics.newImage(mymap.tilesets[1].image)
    
    -- print the width and height of the first layer
    print(mymap.layers[1].width, mymap.layers[1].height)
    

    As for what each piece of the imported data means, you will have to work it out yourself.