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.2.1

Post by Karai17 »

Sensors don't have collision responses, only detections. They are used for walking over top of things like a button that triggers a door to open.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by Karai17 »

It's been quite a while since I've made a formal release, but here we are! STI v1.2.3.0 is now out and supports most of the new features added to Tiled since the big 1.0 version bump. Most of the changes and bug fixes in this release actually came from pull requests, so I am very happy that the LOVE community has chipped in to keep STI functioning while I've been distracted with life and other things. :)

The only feature I am aware of that this release does not currently support is TIled's Text Objects. While I would like to keep STI in feature parity with Tiled, text is one of those things that is a lot more difficult to get right than you'd expect and the amount of work to get text objects working exactly like they do in Tiled begs the question: Is there really a legitimate use for text objects? Does anyone care if they are, or are not in STI? Would a basic implementation be better than none?

As always, please report any bugs or crashes on Github (or here!) and I'll do my best to keep STI maintained as both Tiled and LOVE change and evolve.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
MissDanish
Citizen
Posts: 65
Joined: Wed Mar 07, 2018 11:21 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by MissDanish »

The only feature I would like to see (because it'd make my life a lot easier) would be a way to get the image from an object, I can get the name, x/y coordinates and so on but not the image. I have my own system for dealing with drawing order, so I need that image for things like NPCs or objects that aren't in the background
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by Karai17 »

Can I see an example map? I'd like to see how you are structuring your data so I can determine the best way to add such a feature.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
MissDanish
Citizen
Posts: 65
Joined: Wed Mar 07, 2018 11:21 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by MissDanish »

Karai17 wrote: Wed Mar 27, 2019 12:52 pm Can I see an example map? I'd like to see how you are structuring your data so I can determine the best way to add such a feature.
It won't let me send the map files here, but the way I do it currently is simple but tedious. I add in let's say a light pole (the player needs to be able to walk behind that) and then I add the ID of the image (which corresponds to this image database I have) I want in some custom data attached to the object. The maploader then goes through all the objects and spawns in the object. but to get the image currently it has to look through a database with all the images, since I can't rip the image from the map data with STI's current system.

It'd be much simpler if I could just get the data from the same way you get all the other information from objects (name, x,y etc), like going through all the map objects in a loop. No idea how this would be implemented but something like object.image or some function to get the image would be nice
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by Karai17 »

Hm.. Tiled allows for custom properties and STI respects those, so couldn't you do something like this in Tiled:

Code: Select all

{
  id = 1,
  name = "",
  type = "",
  x = 5,
  y = 20,
  properties = {
    collidable = true,
    image = "assets/images/tree.png"
    -- image = 47 -- if you have an id in a lookup table instead
  }
}
And then this in love:

Code: Select all

for _, object in ipairs(map.objects) do
  if object.properties.image then
    object.properties.image = love.graphics.newImage(object.properties.image)
    -- object.properties.image = db:get(object.properties.image)
  end
end
Or am I misunderstanding something?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
kinderalpha
Prole
Posts: 4
Joined: Mon Dec 23, 2019 7:52 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by kinderalpha »

Hey, I see this thread isn't that active anymore but hoping for some help.

The data structure for this module has my head turning. Trying to figure out how to swap a tile with a different tile (door open, door closed). Dug through a few "solutions" that I can't seem to get to work. Mainly due to the lack of explanation on how to retrieve global ID of a tile at (x, y).

Simply put, does anyone have a working example or explanation for how to swap a tile with another tile from the same tileset? Any help is appreciated. Until then, I'm gonna keep banging my head at this to get it to work. Thanks in advance!
User avatar
master both
Party member
Posts: 262
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by master both »

I had the same problem a while back and this was what I found:

To swap a tile in a layer you need the tile instance that you want to swap, and the new tile that you want, so you can call map:swapTile.

To get the tile instance, you first need to get the it's tile from it's position:

Code: Select all

local layer = map.layers["layer_name"]
local tile = layer.data[y][x] -- tile position (+1 for lua indexing)
then, the only way to find it's instance is to search for it and match it's position (this is the only way that I found to do this):

Code: Select all

local instance = false
local px, py = map:convertTileToPixel(x-1, y-1) -- or (x-1)*map.tilewidth, (y-1)*map.tileheight
for _, ti in pairs(map.tileInstances[tile.gid]) do
	if ti.x == px and ti.y == py then
		instance = ti
		break
	end
end
Now that you have the instance, you need the gid of the new tile (it's the id number on "properties" when you click on a tile in Tiled) and use it to get the tile, then you just call map:swapTile with the instance and the new tile:

Code: Select all

local new_tile = map.tiles[gid]
map:swapTile(instance, new_tile)
I hope this helps :)
Last edited by master both on Tue Dec 24, 2019 12:36 am, edited 2 times in total.
kinderalpha
Prole
Posts: 4
Joined: Mon Dec 23, 2019 7:52 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by kinderalpha »

The way you layed this out makes a lot more sense to me compared to what I've read elsewhere. I understand it now, I just need to know one more detail.
master both wrote: Mon Dec 23, 2019 8:56 pm To get the tile instance, you first need to get the it's tile from it's position:

Code: Select all

local layer = map.layers["layer_name"]
local tile = layer.data[y][x]
What type of x and y value is expected for the layer.data index? On tiled, the door which I want to manipulate is at position (5,8) which correlates to tile position. So in my code I'm doing this.

Code: Select all

            local tile_x, tile_y = tilemap.map:convertTileToPixel(5, 8)
            local layer = tilemap.map.layers['Door']
            local tile = layer.data[tile_y][tile_x]
However, it's giving me an error for indexing a nil value for

Code: Select all

	local tile = layer.data[tile_y][tile_x]
So how should I go about getting the tile x and y if this isn't working?
Thank you so much for the help though, you have no idea how excited I am to tackle this issue.
monolifed
Party member
Posts: 188
Joined: Sat Feb 06, 2016 9:42 pm

Re: Simple Tiled Implementation - STI v1.2.3.0

Post by monolifed »

Why don't you use objects if it is something like a door? Changing the tilelayer feels somewhat strange

and did you try:

Code: Select all

local tile = layer.data[8][5]
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests