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

Post by Karai17 »

rodi wrote:Hi, I am completely new, first time posting on here and am trying to learn Love2D/Lua/STI I've basically done the hello world and went through some basic video tutorials. I'm trying to get the basic example found on the STI github page working, (copied and pasted it verbatim) but I get: module 'sti' not found

I apologize in advance for the dumb question, I have local sti = require "sti" but do I need to install sti somehow? I tried googling and searching this forum but didn't really get an answer, maybe this question is too basic to find a post on. Help?
You need to download the code off of github and put it into your game directory. When you download it, you should get a folder called Simple-Tiled-Implementation-master (or something to that effect) and iside it there area few other folders such as tests, docs, and sti. Copy the sti folder into your game and then require it like the readme states.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
milk
Prole
Posts: 39
Joined: Sun Jul 17, 2016 7:20 pm

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by milk »

Karai17 wrote:You can use the map:convertPixelToTile method convert the player's position to a tile, and then determine which tiles it may be touching base don proximity.
I'm using the bump.lua plugin and I was wondering if there is there any way to do this without having to use integers, for example this:

Code: Select all

love.graphics.print(map:convertScreenToWorld(player.x, player.y), 0, 0, 0, 0.4)
prints '16' when I've collided with the right wall, whereas I'd want the tile property returned as a string, which is in the tiled map's custom properties is specified as 'right_wall'.

i.e

Code: Select all

function collisioncheck()
  if player colliding with tileProperty: 'right_wall' then  -- pseudocode
     player.die() -- just for example
  end
end
What I'm trying to explain is, for each tile with the custom property of 'right_wall' the function player.die is called on collision, (which is handled by bump.lua no?)

rather than

Code: Select all

function collisioncheck()
  if map:convertScreenToWorld(player.x, player.y) == 16 then
     player.die() -- just for example
  end
end
I looked at Map:getTileProperties (layer, x, y) but I'm not overly sure how to implement is as shown in the manner above, any help would be greatly appreciated!
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by Karai17 »

First off, the convert functions returns 2 numbers, not 1, so your code is only interacting with the X axis and not the Y axis. You should store the results of the convert functions into local variables first, and then test.

Code: Select all

local x, y = map:convertScreenToWorld(player.x, player.y)
Also, that function was renamed convertPixelToTile in the most recent version of STI, so you might want to try upgrading.

Finally, the convert function that returns the position in tile/world space should not be giving you an integer, it should be giving you a double. To get the actual tile object, you'd want to do something like the following:

Code: Select all

local x, y = map:convertPixelToTile(player.x, player.y)
local tile = map.layers["Tile Layer 1"].data[math.floor(y)][math.floor(x)]

if tile and tile.properties["right_wall"] then
   player.die()
end
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
4aiman
Party member
Posts: 262
Joined: Sat Jan 16, 2016 10:30 am

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by 4aiman »

Is it possible to desynchronize animation of tiles?
Say, I have animated grass but don't want all animations to be at exact same frame.


Sorry if it was asked and answered before, but the forums' search ignores "STI" as a too short word.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by Karai17 »

You'll need to create several different animations with different starting frames.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
mthwl
Prole
Posts: 3
Joined: Mon Aug 15, 2016 1:11 pm

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by mthwl »

I'm trying something similar to another post (link below) and running into an issue drawing multiple maps. I'm relatively new to Love2d and finding STI to work quite well. Thanks for library!

Possibly relevant post: viewtopic.php?f=5&t=76983&p=192950&hili ... aw#p192950

Right now, I understand my problem to be that if I have two maps loaded, then call each map's draw() function, only the last call the draw() appears to work. It looks like each map.draw() call is clearing the screen (or canvas?)? Maybe I'm going about this in the wrong way.

Goal: load multiple maps, position them using the offset parameters, and draw some of them simultaneously.

In the code below, for instance, map1 will be drawn, then cleared, then map2 will be drawn (leaving a blank area in map1's postiion).

Code: Select all

  local map1 = sti('path/to/map1', {"bump"}, offsetX, offsetY)
  local map2 = sti('path/to/map2', {"bump"}, offsetX, offsetY)
  
  -- ... later in the draw function
  map1:draw()
  map2:draw()
  
Essentially, I'm moving toward a solution in which I can build a "world" made up of an arbitrary number of small maps. As my camera/player move from map to map, I'm able to load newly needed maps into memory, and unload unneeded ones.

Crudely drawn below. Think, as player approaches the right boundary of map1, map2 is loaded and drawn. As player approaches the right boundary of map2, map3 is loaded and drawn, while map1 is unloaded.
[map1][map2][map3]
[map4][map5][map6]
[map4][map5][map6]

Maybe I'm going about this in the wrong way, or completely missing something about how map:draw() works. Any help would be much appreciated!
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by Karai17 »

Each map has its own internal canvas so there should be no overwriting going on. Are you properly using the offsetx and offsety values when creating a new map? Unless you use those offsets, they will all be placed at 0,0.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by bobbyjones »

milk wrote:
Karai17 wrote:You can use the map:convertPixelToTile method convert the player's position to a tile, and then determine which tiles it may be touching base don proximity.
I'm using the bump.lua plugin and I was wondering if there is there any way to do this without having to use integers, for example this:

Code: Select all

love.graphics.print(map:convertScreenToWorld(player.x, player.y), 0, 0, 0, 0.4)
prints '16' when I've collided with the right wall, whereas I'd want the tile property returned as a string, which is in the tiled map's custom properties is specified as 'right_wall'.

i.e

Code: Select all

function collisioncheck()
  if player colliding with tileProperty: 'right_wall' then  -- pseudocode
     player.die() -- just for example
  end
end
What I'm trying to explain is, for each tile with the custom property of 'right_wall' the function player.die is called on collision, (which is handled by bump.lua no?)

rather than

Code: Select all

function collisioncheck()
  if map:convertScreenToWorld(player.x, player.y) == 16 then
     player.die() -- just for example
  end
end
I looked at Map:getTileProperties (layer, x, y) but I'm not overly sure how to implement is as shown in the manner above, any help would be greatly appreciated!
Hello. I wrote the bump plugin and currently the tile properties are added to the collision item in such a way that it can be accessed by doing:

Code: Select all

tile.properties.property
More accurately when you get you return values from world:move you can find the properties table like so:

Code: Select all

for i,v in ipairs(cols) do
v.other.properties.property
end
mthwl
Prole
Posts: 3
Joined: Mon Aug 15, 2016 1:11 pm

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by mthwl »

Re: multiple maps drawing at the same time, in different positions using the offset parameters.

Following up from a few days ago, thanks for the response. I put together a small love file with 4 maps to test this. It loads 4 small maps, positions them, then makes 4 :draw calls. The order matters, the last draw call wins, and only that map is displayed (positioned correctly).

I think I must be missing something about how this is supposed to work. Thanks!
sti-map-test.love
(20.89 KiB) Downloaded 98 times
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.2

Post by Karai17 »

So I think I know what the issue is. Each map's canvas is being cleared before drawing, which is the right thing to do, but the colour it is being cleared with is love's background colour, which is black in this case, but always solid in any other case as well. This means that if the map canvases are over lapping each other, parts will not be shown. The map's canvas is the size of the window. So if you have maps smaller than 1 window size, it will cause issues.

Now, I don't know if the proper fix here is to change the canvas size to be either the size of the map or the size of the window, whichever is smaller; or if I should leave it as-is and tell people maps should be a certain size if you are going to have several of them. Both methods have pros and cons.
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: Bing [Bot] and 27 guests