Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Karai17 »

That would have made the code unreasonably complex for minimal gain, and I needed to render everything to a single batch to fix some rendering issues anyway. I also suspect that the vast majority of people will be making maps 256^2 or smaller, meaning that a single batch would only be 65k tiles. Maps bigger than that are almost always unnecessary and in the case that someone does need to make a huge map, STI supports map offsets so they can just create and load a few individual maps and position them.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Zireael »

Now that STI has the capability to make randomized maps, I've decided to try working with STI. Alas, integrating it with an existing project turned out to be difficult, so I'm starting from scratch again :P
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Zireael »

Karai, I'm having problems accessing the tile data in layer. Specifically, I'm using STI's convertPixeltoTile to know what tile I'm mousing over, then I want to get the gid of that tile to know what kind of a tile it is (wall, floor, etc.). The map is isometric if it matters.

The old method I found in the thread was local tile = self.layers[layer].data[y][x] but I have verified that the self.layers[layer].data doesn't have the [y] or [x] this method expects. I guess this changed at some point. How do I get the gid of the tile if I know it's x and y, then?
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Karai17 »

Map.layers[layer].data[y][x] is definitely still there. Make sure to use math.floor on the y and x values you get from the conversion function, as those values are floating point values (so you can use them to convert back to the correct pixel) and not integers.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Zireael »

Thanks Karai, I managed to figure it out (I was getting the tile under the cursor from love.mouse.getPosition() while I should have used gamera:toWorld().

I'm now wondering how would one implement a FOV with STI, given that STI draws the whole map at once. The part of the map outside FOV would probably have to be masked somehow... maybe I could use the swapTile function to swap the tiles outside FOV for tile 0 (empty)... would that work?
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Karai17 »

Just draw a mask on top of the map. or set a scissor before drawing the map.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
phobos2077
Prole
Posts: 11
Joined: Sun Feb 12, 2017 4:50 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by phobos2077 »

First of all, thanks for an awesome library! A couple of questions.

1. What is the recommended way to dynamically change tiles or objects (add/remove) on the map layer?

2. Should I always update/draw my objects without using STI's object layers? I want to use a component approach for my game objects, but still leverage the STI's object layers for the draw order and stuff. The best approach I see right now is to "transform" each object layer on map load by iterating every object from map data, creating game engine's entity for each Tiled's object, adding this new entity to a custom layer and then deleting the source layer (or making it invisible).

3. Is there some kind of optimization when drawing larger maps? I mean if I create very large map, will STI still draw everything that is not visible on screen? (I'm using hump.camera)
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Karai17 »

1) https://github.com/karai17/Simple-Tiled ... t.lua#L990

2) That is exactly the correct process.

3) STI is already optimized. It batches every tile into a single draw call (per texture, per layer) so there is no performance overhead for drawing the map.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
fonzonzonz
Prole
Posts: 1
Joined: Sat Apr 01, 2017 8:32 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by fonzonzonz »

Hi, I'm having a fair amount of trouble getting STI to do much of anything.

First: Tiled outputs my layer data as a single list, e.g.,

Code: Select all

 data = {
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
      }
but functions like getTileProperties want to access this data like it's a list of lists.

Second, even if I could get this function to work, this isn't where my tile properties are even stored in the first place.

Basically, I'm trying to check if a sprite is on the ground in a platformer-type situation. I want to check if the property "solid" is set for the tiles at my player's feet. I honestly have no idea how to do this using STI's built-in functionality at this point. I appreciate the help. Really, I just wish the documentation provided examples.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post by Karai17 »

STI pre-processes the tiled file into its own structure. layer.data changes from a flat table to a table indexed as [y][x]. There is a tutorial linked on the OP of this forum thread I wrote a year or so ago. http://lua.space/gamedev/using-tiled-maps-in-love
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: Google [Bot] and 4 guests