Re: Simple Tiled Implementation - STI v0.9.7
Posted: Mon Feb 09, 2015 2:32 am
You can set the map's collision data, or you can define a player's min/max x/y positions
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
Code: Select all
print(map:getTileData(layer,x,y).gid)
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
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'
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.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:
What could be the issue? Thanks in advance!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'
Code: Select all
map = sti.new("assets/maps/map-2")