[SOLVED :D]STI Collision Map Help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
lalorobot
Prole
Posts: 16
Joined: Sat Apr 19, 2014 12:06 am
Contact:

[SOLVED :D]STI Collision Map Help

Post by lalorobot » Sat Apr 26, 2014 5:47 pm

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
At first:(Bad art explanation! lol)
Image

After Checking which tiles are collidable:
Image

level.lua

Code: Select all

level = {}

function level.load()
	-- 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	
Thanks in advance :awesome:

EDIT: Added .love I dont know if it will help but whatever :P
Attachments
SurvivalINDEV.love
(2.25 MiB) Downloaded 55 times

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

Re: [SOLVED :D]STI Collision Map Help

Post by lalorobot » Mon Apr 28, 2014 9:30 pm

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

In level.load()

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 :awesome:

User avatar
Karai17
Party member
Posts: 858
Joined: Sun Sep 02, 2012 10:46 pm

Re: [SOLVED :D]STI Collision Map Help

Post by Karai17 » Tue Apr 29, 2014 2:55 pm

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é

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], Google [Bot], pedrosgali and 5 guests