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

Post by Karai17 »

You can set the map's collision data, or you can define a player's min/max x/y positions
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
megalukes
Citizen
Posts: 94
Joined: Fri Jun 27, 2014 11:29 pm
Location: Brazil

Re: Simple Tiled Implementation - STI v0.9.7

Post by megalukes »

Hi there. Is there a way to get a tile id? I just found out how to get a tile properties but not its id. Thanks!

Edit: Just found out how. I created a small function to do it. Now I can access all the tile data too. Here's the code:

Code: Select all

function Map:getTileData(layer, x, y)
	local tile = self.layers[layer].data[y][x]

	if not tile then return {} end

	return tile
end
e.g.:

Code: Select all

print(map:getTileData(layer,x,y).gid)
User avatar
Rucikir
Party member
Posts: 129
Joined: Tue Nov 05, 2013 6:33 pm

Re: Simple Tiled Implementation - STI v0.9.7

Post by Rucikir »

Hi,
I'm having troubles (because I'm just a beginner). Could you give me the basic code to have a map I could translate, and scale (zoom-in, zoom-out) nicely ? Because what I've been doing is rather ugly, and not very much close to what I want.
Or perhaps it is easier to do this with a lib designated for camera management ?
Thank you !

Code: Select all

function love.load ()
    sti = require "Simple-Tiled-Implementation"
    -- map is 1536x2560 px, 12x20 tiles, each tile is 128x128 px
    map = sti.new("map")

    zoom = 1
    translateX, translateY = 0, 0
end

function love.update(dt)
    if love.keyboard.isDown('up') then        translateY = translateY + 20
    elseif love.keyboard.isDown('down') then  translateY = translateY - 20 end
    if love.keyboard.isDown('left') then      translateX = translateX + 20
    elseif love.keyboard.isDown('right') then translateX = translateX - 20 end

    if translateX > 0 then translateX = 0 end
    if translateX < -1536 + love.graphics.getWidth() then translateX = -1536 + love.graphics.getWidth() end
    if translateY > 0 then translateY = 0 end
    if translateY < -2560 + love.graphics.getHeight() then translateY = -2560 + love.graphics.getHeight() end

    map:update(dt)
end

function love.draw()
    love.graphics.push()
    love.graphics.translate(translateX, translateY)
    map:setDrawRange(translateX, translateY, love.graphics.getWidth(), love.graphics.getHeight())
    map:draw(zoom, zoom)
    love.graphics.pop()

    love.graphics.print(tostring(love.timer.getFPS(), 10, 10))
    love.graphics.print(tostring(translateX), 10, 20)
    love.graphics.print(tostring(translateY), 10, 30)
    love.graphics.print(tostring(zoom), 10, 50)
end

function love.mousepressed (x, y, b)
    if b == 'wu' then
        zoom = zoom + 0.1
    elseif b == 'wd' then
        zoom = zoom - 0.1
    end
end

function love.resize(w, h)
    map:resize(w, h)
end
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.7

Post by Karai17 »

What is it you are trying to do, and what is actually happening? Could you provide a love file for me to examine?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Raskol
Prole
Posts: 9
Joined: Mon Mar 03, 2014 1:40 pm
Location: Budapest

Re: Simple Tiled Implementation - STI v0.9.7

Post by Raskol »

Hey Karai

Thanks for STI, really appreciate it. However I'm having a problem I can't seem to fix. I attached my love file(sorry for the mess) so you can check it but I think the problem lies in the way I made the map in tiled. I tested it with your tech demo map and it worked fine so I believe I'm missing some settings or whatever.

I made a basic tileset and added 7 layers to the map. The only difference I see between your and my map is that I have Terrains set up. Otherwise I added the "collidable" "true" properties by hand to the specific tiles. Is there anything else to do? I exported the map in lua and loaded it up, then I get this:

Code: Select all

modules/STI/map.lua:278: attempt to index field 'properties' (a nil value)

Traceback

modules/STI/map.lua:278: in function 'initWorldCollision'
main.lua:35: in function 'load'
[C]: in function 'xpcall'
What could be the issue? Thanks in advance!
Attachments
map.love
(44.45 KiB) Downloaded 101 times
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.7

Post by Karai17 »

Raskol wrote:Hey Karai

Thanks for STI, really appreciate it. However I'm having a problem I can't seem to fix. I attached my love file(sorry for the mess) so you can check it but I think the problem lies in the way I made the map in tiled. I tested it with your tech demo map and it worked fine so I believe I'm missing some settings or whatever.

I made a basic tileset and added 7 layers to the map. The only difference I see between your and my map is that I have Terrains set up. Otherwise I added the "collidable" "true" properties by hand to the specific tiles. Is there anything else to do? I exported the map in lua and loaded it up, then I get this:

Code: Select all

modules/STI/map.lua:278: attempt to index field 'properties' (a nil value)

Traceback

modules/STI/map.lua:278: in function 'initWorldCollision'
main.lua:35: in function 'load'
[C]: in function 'xpcall'
What could be the issue? Thanks in advance!
Your file does not load for me, you didn't copy all of the files. That being said, I notice that you're using an older version of Tiled. Try using 0.11.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Raskol
Prole
Posts: 9
Joined: Mon Mar 03, 2014 1:40 pm
Location: Budapest

Re: Simple Tiled Implementation - STI v0.9.7

Post by Raskol »

Hm, am I? I thought I got the 0.11 version. I think you probably saw the other map file? I included the one from your tech demo for testing, I guess that was created with an older version.

Tried another love file. Now it loads your map by default, you can check the mentioned error message if you modify line 29 in the main file

Code: Select all

map = sti.new("assets/maps/map-2")
map-2 is your tech demo map wich works, map-1 is mine(which don't). Both of them are in the assets/maps folder. Thanks a mil!
Attachments
map2.love
(249.83 KiB) Downloaded 118 times
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.9.7

Post by Karai17 »

Ah, I see the issue. I just pushed a fix. :)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Raskol
Prole
Posts: 9
Joined: Mon Mar 03, 2014 1:40 pm
Location: Budapest

Re: Simple Tiled Implementation - STI v0.9.8

Post by Raskol »

Awesome, it works! Thanks mate
cryptix
Prole
Posts: 5
Joined: Tue Nov 22, 2011 4:31 pm
Contact:

Re: Simple Tiled Implementation - STI v0.9.8

Post by cryptix »

Hi,
First of all, thanks a lot for STI!

But I'm just wondering if there is any support for tiles that contain transparency, sorry if i've missed it. When I draw tiles that are transparent (even though they have tiles on lower layers), the transparent sections appear white.
Post Reply

Who is online

Users browsing this forum: No registered users and 83 guests