[SOLVED :D]STI Collision Map Help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
lalorobot
Prole
Posts: 16
Joined: Sat Apr 19, 2014 12:06 am
Contact:

[SOLVED :D]STI Collision Map Help

First I am quite new to all this and my brain is half dry already so this might be a stupid question.
What I want to know is how to check which tiles are in the collision map and then make a rectangle shape (hardoncollider) at its position
Like this
Red: Bounding Box
Green: Tiles

After Checking which tiles are collidable:

level.lua

Code: Select all

level = {}

-- Grab window size
windowWith = love.graphics.getWidth()
windowHeight = love.graphics.getHeight()

-- Load a map exported to Lua from Tiled
map = sti.new("maps/forest1")
Col = map:getCollisionMap("Collidable")
print(Col)
print(Col.properties)
print('\n')
print("Map.width = " .. map.width)
print('\n')
print("Map.orientation = " .. map.orientation)
print('\n')
print("Map.tileheight = " .. map.tileheight)
print('\n')
print("Map.height = " .. map.height)
print('\n')
print("Map.tilewidth = " .. map.tilewidth)
end

function level.update(dt)
map:update(dt)
end

function level.draw()
local tx = -0
local ty = -7
local w = windowWith
local h = windowHeight

-- Move the top-left-most x/y position by tx/ty, respectively
love.graphics.translate(tx, ty)

-- Draw only the tiles on screen
map:setDrawRange(tx, ty, w, h)
map:draw()
--map:drawCollisionMap(Collision)
end	

EDIT: Added .love I dont know if it will help but whatever
Attachments
SurvivalINDEV.love

lalorobot
Prole
Posts: 16
Joined: Sat Apr 19, 2014 12:06 am
Contact:

Re: [SOLVED :D]STI Collision Map Help

After looking at STI's code I ended up doing this:

Code: Select all

	bounding = {}
local tw = map.tilewidth
local th = map.tileheight
for y=1, map.height do
for x=1, map.width do
local tx, ty
if map.orientation == "orthogonal" then
tx = (x - 1) * tw
ty = (y - 1) * th
end
if Col.data[y][x] == 1 then
TER = Collider:addRectangle(tx, ty, tw, th)
table.insert(bounding, TER)
end
end
end
Right now I have only tested it on one map but it works so i'm happy

Karai17
Party member
Posts: 892
Joined: Sun Sep 02, 2012 10:46 pm

Re: [SOLVED :D]STI Collision Map Help

STI doesn't have native collision detection, so yeah you need to roll your own. I'm glad you got it working.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

Who is online

Users browsing this forum: No registered users and 10 guests