Page 22 of 92

Re: Simple Tiled Implementation - STI v0.7.5

Posted: Wed Sep 10, 2014 4:53 pm
by Rockford
Hi,

How would I go about accessing the tile information in order to draw different colored squares
for each tile, with STI?

On my own simple map I used this:

Code: Select all

for i,v in ipairs(map) do
		if v.kind == 1 then
		      love.graphics.setColor(0,255,0)
 		      love.graphics.rectangle("line", v.x, v.y, v.width, v.height)
		      love.graphics.setColor(255,255,255)
		end
		if v.kind == 2 then
		      love.graphics.setColor(0,255,255)
		      love.graphics.rectangle("line", v.x, v.y, v.width, v.height)
		      love.graphics.setColor(255,255,255)
		end
		if v.kind == 3 then
		      love.graphics.setColor(0,0,255)
		      love.graphics.rectangle("line", v.x, v.y, v.width, v.height)
		      love.graphics.setColor(255,255,255)
		end
		if v.kind == 4 then
		      love.graphics.setColor(255,0,255)
		      love.graphics.rectangle("line", v.x, v.y, v.width, v.height)
		      love.graphics.setColor(255,255,255)
		end
	end
I still get really confused with how to access tables within tables, and all that sort of stuff. So how would I go about getting the information needed to draw those squares? I included the "kind" property when in tiled, so I can see it in my map file.

Any help would be appreciated, even a point in the right direction.

Thanks

Re: Simple Tiled Implementation - STI v0.7.5

Posted: Wed Sep 10, 2014 6:28 pm
by Karai17
The Map object is simply a big table filled with lots of other tables. Inside Map is a table called layers which holds each layer's data. Inside each layer is a table called tiles which holds each tile an dis organized via y/x.

So to access each tile, you need to do the following:

Code: Select all

local layer = map.layers.some_layer

for y, tiles ipairs(layer) do
    for x, tile in ipairs(tiles) do
        if tile.property.kind == 1 then
            -- etc
        end
    end
end
Make sure to read the documentation to get a better idea of how it all works.

Re: Simple Tiled Implementation - STI v0.7.5

Posted: Thu Sep 11, 2014 3:39 am
by Rockford
Ah, okay I see. I was looking at the map file that was exported from Tiled.

Thanks for the help!

Re: Simple Tiled Implementation - STI v0.7.5

Posted: Wed Sep 17, 2014 10:41 am
by Macpon7
Hello.
I was thinking of using this as a way to import compact maps into a 2D platformer, which I think this is ideal for. I have the map import working, but I was wondering how I would go about making one of the layers(the second one, "Collision Layer") into a static object for the love.physics module, as I want to use this in my game for movement of all objects.
Thanks in advance :)

Re: Simple Tiled Implementation - STI v0.7.5

Posted: Wed Sep 17, 2014 2:58 pm
by Karai17
This is something I am actually planning to implement soon. Since Tiled 0.10 has been released, full collision support is now on the roadmap for STI.

Re: Simple Tiled Implementation - STI v0.7.5

Posted: Wed Sep 17, 2014 3:28 pm
by Macpon7
Ok, cool. Is there a way to do this currently? I know there is a getCollision(or something like that), but how do I use this for collision in my game?

Re: Simple Tiled Implementation - STI v0.7.5

Posted: Wed Sep 17, 2014 3:31 pm
by Karai17
getCollisionMap returns a layer table with binary data (the map tiles are either 0 or 1). You can use AABB collision detection over each "1" tile to stop the player form moving onto it.

https://www.youtube.com/watch?v=ghqD3e37R7E

Re: Simple Tiled Implementation - STI v0.7.5

Posted: Wed Sep 17, 2014 3:56 pm
by Macpon7
Thanks!

Re: Simple Tiled Implementation - STI v0.7.6

Posted: Thu Sep 18, 2014 12:50 am
by Karai17
Just pushed an update! While this does not yet have the new animation or collision features of Tiled, it does give much needed support for isometric and staggered maps. I'll start working on the new Tiled features soon, though, so stay tuned!

Re: Simple Tiled Implementation - STI v0.7.6

Posted: Fri Sep 19, 2014 1:03 am
by Clean3d
Hi Karai17, have you started work on animation yet or have any idea on the timeframe for it? I'm asking because I'm also working on it, and I don't want to duplicate efforts if I don't have to. I'm also willing to share what I've come up with, but I haven't contributed to a project I didn't write myself, so I'm not confident my code is up to par.

So far, I've added frame and time properties to each tile definition, and that global definition gets iterated with map:update(). To change the individual tiles in the data, I just add them to a list by GID during Map:setSpriteBatches and include a reference to their batch and the id returned by SpriteBatch:set. Whenever the global 'frame' of a tileset tile changes, I just do a for _, t in pairs( animatedTiles[gid] and swap the quad in the spritebatch. It's sort of working, except I have a bug when I reference the GID of certain tiles... If anyone has an animated tileset or Tiled map they would like to share, it would help me test my code against different usage cases.

Anyway, I look forward to hearing back from you, Karai17.