Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
Rockford
Prole
Posts: 26
Joined: Fri Mar 14, 2014 9:40 pm
Location: USA

Re: Simple Tiled Implementation - STI v0.7.5

Post 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
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.7.5

Post 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.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Rockford
Prole
Posts: 26
Joined: Fri Mar 14, 2014 9:40 pm
Location: USA

Re: Simple Tiled Implementation - STI v0.7.5

Post by Rockford »

Ah, okay I see. I was looking at the map file that was exported from Tiled.

Thanks for the help!
Macpon7
Prole
Posts: 7
Joined: Mon Sep 15, 2014 9:05 am

Re: Simple Tiled Implementation - STI v0.7.5

Post 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 :)
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.7.5

Post 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.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Macpon7
Prole
Posts: 7
Joined: Mon Sep 15, 2014 9:05 am

Re: Simple Tiled Implementation - STI v0.7.5

Post 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?
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.7.5

Post 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
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Macpon7
Prole
Posts: 7
Joined: Mon Sep 15, 2014 9:05 am

Re: Simple Tiled Implementation - STI v0.7.5

Post by Macpon7 »

Thanks!
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.7.6

Post 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!
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Clean3d
Prole
Posts: 30
Joined: Fri Mar 29, 2013 4:16 pm

Re: Simple Tiled Implementation - STI v0.7.6

Post 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.
Clean3d's Twitter, Game, and Blog
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest