0
\$\begingroup\$

I'm trying to use a pretty standard map with the Simple Tiled Implementation module for Love2D, but no matter what I try, I can't get it to display anything but a black screen. Here's my current code (keybindings in an effort to see if the map has just been placed offscreen):

local sti = require "sti"
local mapPos = { x = 0, y = 0 }

function love.load()
   map = sti("maps/map1.lua")
end

function love.update(dt)
   if love.keyboard.isDown("w") or love.keyboard.isDown("up") then
      mapPos.y = mapPos.y - 5
   end

   -- Move player down
   if love.keyboard.isDown("s") or love.keyboard.isDown("down") then
      mapPos.y = mapPos.y + 5
   end

   -- Move player left
   if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
      mapPos.x = mapPos.x - 5
   end

   -- Move player right
   if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
      mapPos.x = mapPos.x + 5
   end
   map:update(dt)
end

function love.draw()
   -- Transform world
   love.graphics.translate(-mapPos.x, -mapPos.y)

   -- Draw world
   map:draw()
end

However, even a more basic attempt (copied from the STI tutorial linked from the README on the Github page) doesn't work, again giving a black screen:

-- Include Simple Tiled Implementation into project
local sti = require "sti"

function love.load()
    -- Load map file
    map = sti("map.lua")
end

function love.update(dt)
    -- Update world
    map:update(dt)
end

function love.draw()
    -- Draw world
    map:draw()
end

My directory structure is basically just main.lua, an assets folder, and a maps folder. The maps folder contains the Tiled tile set and the Tiled .tmx maps and the lua exported maps.

I'm on Mac OSX, using Love2D version 0.10.2.

Am I missing something? Thanks.

\$\endgroup\$
  • \$\begingroup\$ Hmm, when I paste your second snippet into a main.lua and put it in the STI repository root, and change the map from "map.lua" to "tests/ortho.lua", and run "love .", it simply works for me. Is there no error message displayed at all? Did you try it with the example map instead of your own? \$\endgroup\$ – Thorbjørn Lindeijer Feb 12 '18 at 8:28
  • \$\begingroup\$ I fixed it. It was a problem with exporting my lua map. \$\endgroup\$ – Christopher Dumas Feb 12 '18 at 20:09
0
\$\begingroup\$

I realized you need to be careful exporting lua maps from Tiled, because they are automatically named like "[your map name]..lua". I'm not sure why this is, but when I did Export As instead and named the file manually, it worked.

\$\endgroup\$
  • \$\begingroup\$ Hmm, it's not supposed to add a double dot of course. I can't reproduce this problem on Linux. What operating system are you on? \$\endgroup\$ – Thorbjørn Lindeijer Feb 13 '18 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.