Tiled and Advanced Tiled Loader

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
munchor
Prole
Posts: 39
Joined: Sun Jun 10, 2012 4:28 pm

Tiled and Advanced Tiled Loader

Post by munchor »

Hey everyone,

I started using Love2D yesterday and I am experiencing a rather strange issue with Tiled and AdvTiledLoader.

This is my code:

Code: Select all

lick = require "lick"
lick.reset = true

TILE_SIZE = 25
MAP_WIDTH = 26
MAP_HEIGHT = 24
N_MAPS = 1

function love.load()
  -- Set up player
  player = {}
  player.x = 0
  player.y = 0
  player.speed = 1000

  -- Load all map images
  map_loader = require("AdvTiledLoader.Loader")
  map_loader.path = "maps/"
  maps = {}
  for i = 1, N_MAPS do
    maps[i] = map_loader.load("map" .. i .. ".tmx")
  end
end

function love.update(dt)
  if love.keyboard.isDown("right") then
    player.x = player.x + player.speed * dt
  end
  if love.keyboard.isDown("left") then
    player.x = player.x - player.speed * dt
  end
  if love.keyboard.isDown("down") then
    player.y = player.y + player.speed * dt
  end
  if love.keyboard.isDown("up") then
    player.y = player.y - player.speed * dt
  end
end

function love.draw()
  love.graphics.push()
  maps[1]:draw()
  love.graphics.pop()

  --love.graphics.rectangle("fill", player.x, player.y, TILE_SIZE, TILE_SIZE)
end
My map file (which I created using Tiled) looks like this:

111111
100001
100001
111111

It's a square, with gray blocks on borders and filled with black. However, when I draw it, I get this:
dm9rs.png
dm9rs.png (84.88 KiB) Viewed 148 times
I don't see the first row and the first column for some reason, but they are there, I drew and can see them on Tiled.

Any idea? Thank you.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Tiled and Advanced Tiled Loader

Post by Jasoco »

Just hazarding a guess, but it's because you're only drawing from 1 instead of from 0. I'm assuming the Tile Loader loads the map into a grid that has its left and top tiles at 0. But you are only drawing from 1. So start drawing from index 0. If you can figure out how that is. I'm assuming the solution will be inside whatever function maps[1]:draw() is. I'm not familiar with the inner workings of the Tiled loader though so someone else would have to help there. I just know what I see. And I've seen that before many times. It's the old "Accidentally started at 1 instead of 0" problem.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Tiled and Advanced Tiled Loader

Post by Kadoba »

There was a bug with drawing the map without setting the draw range (one I swear I fixed a while back). Try the updated version and see if it still gives you a problem.
Just hazarding a guess, but it's because you're only drawing from 1 instead of from 0.
That was exactly it. In version 0.10.0 ATL switched to drawing from 0 instead of 1. If the draw range isn't set then it defaulted to (1,1,width,height). This bug was found and fixed shortly afterwards but I guess it somehow didn't make it into the repo.
munchor
Prole
Posts: 39
Joined: Sun Jun 10, 2012 4:28 pm

Re: Tiled and Advanced Tiled Loader

Post by munchor »

The new version worked, please update the Github repository please, though :)
Last edited by munchor on Sun Jun 10, 2012 5:57 pm, edited 1 time in total.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Tiled and Advanced Tiled Loader

Post by kikito »

Yes, there was a bug. It was fixed one hour ago by kadoba. You can see the changes in a repo on its "commits" page:

https://github.com/Kadoba/Advanced-Tile ... its/master
When I write def I mean function.
munchor
Prole
Posts: 39
Joined: Sun Jun 10, 2012 4:28 pm

Re: Tiled and Advanced Tiled Loader

Post by munchor »

kikito wrote:Yes, there was a bug. It was fixed one hour ago by kadoba. You can see the changes in a repo on its "commits" page:

https://github.com/Kadoba/Advanced-Tile ... its/master
Oh, good point, thanks :)
Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests