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

Post by Karai17 »

If you remove all the layers then ipairs can't find anything and it will throw an error.

In the orthogonal map, the sprite is embedded directly into the sprite layer so it is only updated when that layer is updated, same with draw.

STI updates and draws layers in order, so if you have a tile layer over top of your sprite layer, then your sprite will be drawn below those tiles. Make sure your order is correct and nothing is being hidden behind tiles.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Elemental
Prole
Posts: 5
Joined: Tue May 19, 2015 2:13 am

Re: Simple Tiled Implementation - STI v0.9.8

Post by Elemental »

Ah right if all the layers are deleted then there wont be any layers for STI to iterate over, but the issue comes from only have one layer, specifically a tile layer, rather than multiple different layers. I have finally figured how how to successfully render the custom sprite added to the project, in the Orthogonal that would be kim.jpg.

I found that this sprite seems to only be drawn after a second layer is added to the map. Hence if a new map is created, with only a tile layer, no custom sprites will render, however if an object layer is added then the custom sprite renders.

Ah ha! I found the issue, well not directly.

So I was able to get the sprite to render with only have one layer, it seems the issue comes from when the map adds a custom layer and if the depth of the layer is set at a depth higher than the total number of layers (+1)? I'm not sure if the layers are indexed by one or not.

So in the example the map added a custom layer named "Sprite Layer" and passed in the parameter 3, so if there is one layer, then this one won't be rendered because there is a missing layer 2, by changing the 3 to a 2 the sprite now renders. Additionally by incremented the index from 3 to 4 or 5, the same issue stays. Lastly I find it a bit odd if say adding a custom layer and the index is the same as an already existing layer, as it does seem to render everything like it should, but this is a pretty strange discrepancy.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.8

Post by Karai17 »

If the layer already exists, it simply inserts it and pushes everything else up.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Fern Silverthorn
Prole
Posts: 3
Joined: Sun Jun 07, 2015 3:31 am

Re: Simple Tiled Implementation - STI v0.9.8

Post by Fern Silverthorn »

Hey, first I want to say that your library was how I discovered Love. I was looking for a game engine that could be used with tiled because I was sick of making maps by hand and through the supported games engines I saw love2d and the supporting library was yours. :awesome:

I have made a simple test of your library just to wet my feet before I actually take the time to Organize and compartmentalize my code in preparation for something more long term and I keep on running into a very odd glitch where tiles are rendering fine when standing still, but when the camera moves the tile position update makes horizontal artifacts.

I suspect floating point errors but I figured you would know best. I could add a 2px buffer to all my tiles, But is not very elegant so I was hoping you know a better way.

This was very difficult to capture, I was only able to because rarely when the player stops moving it is perfectly on a seam-line frame
Image

Update: It seems to only happen regularly at the peak of a jump when the vector is not vertical I guess when gravity makes the players position change too accurately with tiny decimals.
Maybe I should give the camera a little lag time?


Update2: I isolated the issue by chance. If Tilemap:setDrawRange(x, y, width, height) receives a decimal n + 0.5 for x or y the rounding function dies. solution was to have n + 0.5 vaules changed to n + 0.51 before calling the function
Attachments
STI Test.love
The code in Question
(93.32 KiB) Downloaded 205 times
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.8

Post by Karai17 »

Hey, sorry the the excessively late reply!

So this issue is caused by scaling. You can try one of two things to fix this.

1) put your scaleX and scaleY value sinto map:draw

2) do the above and in sti/map.lua line 784, add love.graphics.scale(sx, sy) and remove the sx, sy from framework.draw()

Let me know your results!
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Fern Silverthorn
Prole
Posts: 3
Joined: Sun Jun 07, 2015 3:31 am

Re: Simple Tiled Implementation - STI v0.9.8

Post by Fern Silverthorn »

Thanks a lot for the response! It came at the right time as I just "finished" a boilerplate for love and got my artist to start work on some *actual* art to replace my terribad placeholder stuff that I'd made (and acquired from open game art in the case of tiles).
Considering the high quality of your documentation it was completely my fault for not realizing that I would need to do my own rounding if I wanted my own scaling to work.

I have another question do objects have accessible x/y values in layers? I want to use A* for pathfinding which needs to know node data to be able to make a node graph. I could have a separate file or something but it would be nice to be able to edit stuff like that from tiled.
Could I modify your code that checks for collide=true to check for nodex and nodey as well? or do objects, for instance a rectangle have something like layer.indexofobject.x
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.8

Post by Karai17 »

For actual objects, they should each have an x and y location. For tiles, you're going to need to to either count them or run some pixel point on the screen through one of the convert functions to convert it from screen space to tile space (and then cut off the decimal).
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
pevzi
Prole
Posts: 27
Joined: Tue Apr 02, 2013 4:09 pm
Contact:

Re: Simple Tiled Implementation - STI v0.9.8

Post by pevzi »

Hello, it's me again. Running my game under ProFi I've noticed that STI spends too much time in drawObjectLayer method. I've found out that it draws (or at least tries to draw) rectangular shapes even for tile objects which normally have their width and height set to 0. This results in nothing being drawn yet greatly affects performance. Since tile objects are not meant to have non-zero width and height is it really necessary to do the extra work? I've seen you've mentioned that rectangles shouldn't be drawn in this case but it looks like some users may rely on this [undocumented] functionality.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Simple Tiled Implementation - STI v0.9.8

Post by Eamonn »

Had a brief look through the thread, and I couldn't find any information on how to do this. Maybe I'm just blind, but I couldn't find this in the documentation either, and it just seems like something really basic and something that should be easy to do.

Anyway, how do I loop through all the tiles in the map/layer and get all their properties? For example, maybe something like:

Code: Select all

for i,tile in ipairs(map.tiles) do -- or maybe ipairs(layer.tiles)?
  print('Tile X: ' .. tostring(tile.x) .. '\nTile Y: ' .. tostring(tile.y))
end
How can one achieve this? I'm pretty sure you can do this (I believe it was possible in ATL), because as I said it's a pretty fundamental thing to be able to do :3

Thanks in advance!
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.8

Post by Karai17 »

Code: Select all

local layer = map.layers["Tile Layer 1"]

for y=1, #layer.data do
   for x=1, #layer.data[y] do
      local tile = layer.data[y][x]

      if tile then
         -- do a thing
      end
   end
end
@pevzi: That's a point. Tile object probably shouldn't have an outline, eh?
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: No registered users and 1 guest