Loading Tiled Lua Maps

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
User avatar
TheMeq
Citizen
Posts: 56
Joined: Fri Sep 02, 2011 9:56 pm
Location: Nottingham, UK

Loading Tiled Lua Maps

Post by TheMeq »

Hi all, I have a new problem :P

I am exporting maps from tiled in the lua format with no compression or anything like that. I've create a loader (well, I thought I had) which reads the data from the file as needed and opens it up, but when I launch, it just goes to a black screen after the splashes, and I'm not sure why. Maybe I don't quite understand tables correctly. Would you mind looking at my code and seeing where I've made a mistake? I've included the love file which also contains the map file. the tileset.pck is just a png file with a different extension. Thanks

Code: Select all

Game = {}

g_quads = {}
g_layer = {}
g_events = {}

function Game:load()
	g_map = require("maps/el_starters_quarter.lua")
	g_til = love.graphics.newImage("graphics/tileset.pck")
	g_mapsize_w = g_map.width
	g_mapsize_h = g_map.height
	g_tile_w = g_map.tilewidth
	g_tile_h = g_map.tileheight
	g_tileset_w = g_map.tilesets[1].imagewidth / g_tile_w
	g_tileset_h = g_map.tilesets[1].imageheight / g_tile_h
	for t_y = 0,g_tileset_h do
		t_x = 0,g_tileset_w do
			t_quad = love.graphics.newQuad(t_x * g_tile_w,t_y * g_tile_h, g_tile_w, g_tile_h, g_til:getDimensions())
			g_quads[#g_quads + 1] = t_quad
		end
	end
	for t_l = 1,#g_map.layers do
		if g_map.layers[t_l].type == "tilelayer" then
			g_layer[#g_layer + 1] = g_map.layers[t_l].data
		end
		if g_map.layers[t_l].type == "objectgroup" then
			for t_o = 0,#g_map.layers[t_l].objects do
				g_events[#g_events + 1] = {o_t=g_map.layers[t_l].objects[t_o].type,o_x=g_map.layers[t_l].objects[t_o].x,o_y=g_map.layers[t_l].objects[t_o].y,p=g_map.layers[t_l].objects[t_o].properties}
			end
		end
	end
end

function Game:update(dt)
	
end

function Game:draw()
	for t_l = 1,#g_layer do
		t_i = 1
		for d_y = 0,g_mapsize_h do
			for d_x = 0,g_mapsize_w do
				love.graphics.draw(g_til,g_quads[g_layer[t_l][t_i]],d_x * g_tile_w, d_y * g_tile_h)
				t_i = t_i + 1
			end
		end
	end
end

return Game
game.love
No error's are returned, just a black screen. Thanks
(3.96 MiB) Downloaded 141 times
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: Loading Tiled Lua Maps

Post by Zeliarden »

hump.gamestate uses init() instead of load()
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Loading Tiled Lua Maps

Post by Karai17 »

You can try using my library STI (see my signature), it is a fully featured Tiled library.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Post Reply

Who is online

Users browsing this forum: No registered users and 201 guests