Advanced Tiled Loader - No longer maintained

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: Advanced Tiled Loader

Post by rokit boy »

I'm getting an error! That layer is a nil value!

My code:

Code: Select all

--
--  Platformer Tutorial
--

local loader = require "AdvTiledLoader/Loader"
-- set the path to the Tiled map files
loader.path = "maps/"

local HC = require "HardonCollider"

local hero
local collider
local allSolidTiles

function love.load()
	
	-- load the level and bind to variable map
	map = loader.load("level.tmx")
	
	-- load HardonCollider, set callback to on_collide and size of 100
	collider = HC(100, on_collide)
	
	-- find all the tiles that we can collide with
	allSolidTiles = findSolidTiles(map)
	
	-- set up the hero object, set him to position 32, 32
	setupHero(32,32)
	
end

function love.update(dt)
	
	-- do all the input and movement
	
	handleInput(dt)
	updateHero(dt)
	
	-- update the collision detection
	
	collider:update(dt)
	
	
end

function love.draw()
	
	-- scale everything 2x
	love.graphics.scale(2,2)
		
	-- draw the level
	map:draw()
	
	-- draw the hero as a rectangle
	hero:draw("fill")
end

function on_collide(dt, shape_a, shape_b, mtv_x, mtv_y)
	
	-- seperate collision function for entities
	collideHeroWithTile(dt, shape_a, shape_b, mtv_x, mtv_y)
	
end

function collideHeroWithTile(dt, shape_a, shape_b, mtv_x, mtv_y)
	
	-- sort out which one our hero shape is
	local hero_shape, tileshape
	if shape_a == hero and shape_b.type == "tile" then
		hero_shape = shape_a
	elseif shape_b == her and shape_a.type == "tile" then
		hero_shape = shape_b
	else
		-- none of the two shapes is a tile, return to upper function
		return
	end
	
	-- why not in one function call? because we will need to differentiate between the axis later
	hero_shape:move(mtv_x, 0)
	hero_shape:move(0, mtv_y)
	
end

function setupHero(x,y)
	
	hero = collider:addRectangle(x,y,16,16)
	hero.speed = 50
--	hero.img = love.graphics.newImage("img/hero.png")

end

function handleInput(dt)
	
	if love.keyboard.isDown("left") then
		hero:move(-hero.speed*dt, 0)
	end
	if love.keyboard.isDown("right") then
		hero:move(hero.speed*dt, 0)		
	end
	if love.keyboard.isDown("up") then
		
	end
	
end

function updateHero(dt)
	
	-- apply a downward force to the hero (=gravity)
	hero:move(0,dt*50)
	
end

function findSolidTiles(map)
	
	local collidable_tiles = {}
	
	-- get the layer that the tiles are on by name
	local layer = map.tl["ground"]
	
	for tileX=1,map.width do
		for tileY=1,map.height do
			local tile
			
			if layer.tileData[tileY] then
				tile = map.tiles[layer.tileData[tileY][tileX]]
			end
			
			if tile and tile.properties.solid then
				local ctile = collider:addRectangle((tileX-1)*16,(tileY-1)*16,16,16)
				ctile.type = "tile"
				collider:addToGroup("tiles", ctile)
				collider:setPassive(ctile)
				table.insert(collidable_tiles, ctile)
			end
			
		end
	end
	
	return collidable_tiles
end
Yes, it is form a tutorial.
u wot m8
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Advanced Tiled Loader

Post by Robin »

Please upload a full .love, then we are able to help you better.
Help us help you: attach a .love.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: Advanced Tiled Loader

Post by rokit boy »

fil
Attachments
gamgmagma.love
love 0.8.0 BLAD
(70.23 KiB) Downloaded 174 times
u wot m8
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: Advanced Tiled Loader

Post by rokit boy »

rokit boy wrote:fil
ANYONE?
u wot m8
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: Advanced Tiled Loader

Post by rokit boy »

Ok fixed everything but now when I collide with the floor the rectange(player) jumps up and down!
u wot m8
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Advanced Tiled Loader

Post by bartbes »

Stop. Double. Posting. Now.
(And a triple-posting is a double double-post, so that will get you to being banned twice as fast!)
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

ATL version 0.10.0 is out. Added support for Tiled version 0.8.0 including polygon objects, polyline objects, tile offsets, tile rotation, and tileset properties. I haven't extensively tested it with love 0.8.0 yet but it appears to be working fine. Please report any weird things.

One of the most drastic changes was the switch from 2d arrays to a new grid class and the way tiles were stored in tileData. Working with tiles is much easier now with the grid class. No more nil errors! Tiles are now directly referenced in tileData so you don't have to look their IDs up anymore.

So this is how you would get tile (x,y) the old way:

Code: Select all

tile = map.tiles[ map.tileLayers.layerName.tileData[y-1][x-1] ]
Here's the new way:

Code: Select all

tile = map.tileLayers.layerName.tileData(x,y)
The old way was really awful and confusing. Sorry it's been like that for so long.

Changes:
0.10.0 (04/11/12)
- 2d arrays are replaced with a much easier to use grid class.
- Tiles are now directly inserted into TileLayer.tileData. You no longer have to look them up via
their ID in Map.tiles.
- Tile indexes are now the same as their coordinants as shown inside the Tiled.
- Added support for Tiled version 0.8.0. This includes tile rotation, polygon objects,
polyline objects, tilemap offset, and tilemap propterties.
- Moved the object drawing code from object layers to the objects themselves.
- Added functions tileCopy(), tilePaste(), tileRotate(), tileFlipX(), tileFlipY() to TileLayers.
arbaces
Prole
Posts: 6
Joined: Sun Mar 25, 2012 6:44 pm

Re: Advanced Tiled Loader

Post by arbaces »

Thanks for the ATL update! =D

For 0.8.0 compatibility, on line 58 of main.lua, I think love.event.push('q') should be changed to love.event.push('quit').
arbaces
Prole
Posts: 6
Joined: Sun Mar 25, 2012 6:44 pm

Re: Advanced Tiled Loader

Post by arbaces »

I know that double posting is super evil and bartbes is going to kick my butt, but here I go...

I use ATL for the game I'm developing, so I was wondering if you could comment on whether the following behavior is possible and easy to do. If it is easy to do, maybe it's worth including in the main release of ATL:

- When you zoom in, the enviroment tiles stay really crisp. The images might distort a bit, but the pixels are never blurred. However, the character becomes blurry. I assume this is because the x,y coordinate of the character after translation becomes non-integral. (Should I include a screenshot, or do you know what I mean?) Is there any logic which could be added to Char.draw() such that the character is crisply drawn regardless of the global.scale?

- If you set global.scale to values which aren't integer numbers divided by five, then there are sometimes horizontal and vertical lines. I assume these are seams because the ground's tiles aren't being scaled to the exact number of pixels needed, but I don't understand some of the logic in ATL yet. Is it possible to adjust the code such that the tiles won't have these seams?


In my game, I would like different spaces to have different zoom levels. I would also like to have "cinematic" moments where the camera slowly pans out to reveal a bigger space. It won't be possible without this behavior. If you don't know the answer to these questions but are interested, I can continue working on these and report back. =D
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

arbaces wrote: For 0.8.0 compatibility, on line 58 of main.lua, I think love.event.push('q') should be changed to love.event.push('quit').
Thanks. I'll get this fixed tomorrow.
arbaces wrote: - When you zoom in, the enviroment tiles stay really crisp. The images might distort a bit, but the pixels are never blurred. However, the character becomes blurry. I assume this is because the x,y coordinate of the character after translation becomes non-integral. (Should I include a screenshot, or do you know what I mean?) Is there any logic which could be added to Char.draw() such that the character is crisply drawn regardless of the global.scale?
This sounds like it's the image filter. By default the image filter is set to linear which blurs the image when scaled. You probably want the filter to be set to nearest. Just set the image of the character image using image:setFilter("nearest", "nearest"). Or you can set this as the default filter by using love.graphics.setDefaultImageFilter("nearest","nearest").
- If you set global.scale to values which aren't integer numbers divided by five, then there are sometimes horizontal and vertical lines. I assume these are seams because the ground's tiles aren't being scaled to the exact number of pixels needed, but I don't understand some of the logic in ATL yet. Is it possible to adjust the code such that the tiles won't have these seams?
That's not quite an ATL thing. Scaling is the culprit though. When you draw with decimal coordinates then the image isn't guaranteed to "fit" together. The easiest fix for this is to render what you want on a canvas at 1:1 scaling and then scale the canvas up and down.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests