Page 32 of 92

Re: Simple Tiled Implementation - STI v0.9.7

Posted: Mon Feb 09, 2015 2:32 am
by Karai17
You can set the map's collision data, or you can define a player's min/max x/y positions

Re: Simple Tiled Implementation - STI v0.9.7

Posted: Tue Feb 10, 2015 1:26 am
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)

Re: Simple Tiled Implementation - STI v0.9.7

Posted: Fri Feb 20, 2015 10:14 am
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

Re: Simple Tiled Implementation - STI v0.9.7

Posted: Sat Feb 21, 2015 7:26 pm
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?

Re: Simple Tiled Implementation - STI v0.9.7

Posted: Thu Mar 19, 2015 4:20 pm
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!

Re: Simple Tiled Implementation - STI v0.9.7

Posted: Sat Mar 21, 2015 5:58 am
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.

Re: Simple Tiled Implementation - STI v0.9.7

Posted: Sun Mar 22, 2015 9:18 am
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!

Re: Simple Tiled Implementation - STI v0.9.7

Posted: Mon Mar 23, 2015 12:17 am
by Karai17
Ah, I see the issue. I just pushed a fix. :)

Re: Simple Tiled Implementation - STI v0.9.8

Posted: Mon Mar 23, 2015 7:00 am
by Raskol
Awesome, it works! Thanks mate

Re: Simple Tiled Implementation - STI v0.9.8

Posted: Sat Apr 04, 2015 6:33 pm
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.