Page 1 of 1

STI and collision

Posted: Fri May 01, 2020 11:17 pm
by ZephB
Hi,
I have really searched around the Internet to know how to have simple collisions working with my little game. I want to use STI because it's so simple to implement, but how to make simple collisions without using box2d? If this subject is already well responded can you guys refer me to the topic, because right now I'm a little bit strugling. I'm coming form pico-8 so all of this is new to me

Re: STI and collision

Posted: Fri May 01, 2020 11:56 pm
by JuanjoSalvador
It's funny, I switched from Love2D to PICO-8 few years ago, and then back to Love2D again.

I think I already answered this on Reddit too, but in a nutshell, using Box2D plugin is your best choice, imho. If you don't need gravity, you can set gravity to 0 when creating the World object.

Re: STI and collision

Posted: Sat May 02, 2020 12:22 am
by ZephB
Honestly that's funny because 2 years ago I tried love2d found it too complicated and then switched to pico-8 ha ha ha. Should I draw the tilemap myself, would it be easier for me to test collisions?

Re: STI and collision

Posted: Sat May 02, 2020 11:15 am
by pgimeno
For axis-aligned rectangles (AABBs), I recommend the Bump library, https://github.com/kikito/bump.lua

STI contains a plugin for bump, no idea how they're used together though. I haven't used STI myself.

Re: STI and collision

Posted: Sat May 02, 2020 12:06 pm
by JuanjoSalvador
ZephB wrote: Sat May 02, 2020 12:22 am Should I draw the tilemap myself, would it be easier for me to test collisions?
Depending of the complexity of your tileset, but I would say no. Can you provide a .love file or something we can see?

Re: STI and collision

Posted: Sat May 02, 2020 4:44 pm
by ZephB
JuanjoSalvador wrote: Sat May 02, 2020 12:06 pm
ZephB wrote: Sat May 02, 2020 12:22 am Should I draw the tilemap myself, would it be easier for me to test collisions?
Depending of the complexity of your tileset, but I would say no. Can you provide a .love file or something we can see?
Actually I have found the perfect solution. The cartographer library! It is capable of doing the same thing as what pico-8 is capable, it's really great. I've had somme issues so I created my own function in cartographer that allow me to quickly put a map, a tile_number and a property and that returns true or false, exactly like fget in pico-8. I'm really happy with it. This is what I added :

Code: Select all

function pget(map,gid,propertyName)
    local prespect
	if gid == false or gid == nil then
		prespect = false
		return false
	else
		prespect = map:getTileProperty(gid,propertyName)
		if prespect then
			return true
		else
			return false
		end
	end
end

Re: STI and collision

Posted: Sat May 02, 2020 5:36 pm
by JuanjoSalvador
Perfect :)

Re: STI and collision

Posted: Sun May 03, 2020 5:03 am
by cristoferfb
Love2D documentation have a nice list of tutorials:

https://love2d.org/wiki/Category:Tutorials

The first in the list have a very nice explication about 2D collisions:

https://sheepolution.com/learn/book/13

It have too a very compressive introduction to tiles and collisions:

https://sheepolution.com/learn/book/18

U can learn it and then implement a solution for ur problem, love requiere a little more work than PICO but the flexibility is certainly bigger. The documentation is your best friend in any code adventure✌️.

Re: STI and collision

Posted: Tue May 05, 2020 9:27 pm
by kuzika
Wow this really helped me a lot. Thanks 😀

Re: STI and collision

Posted: Fri Nov 27, 2020 10:04 pm
by MadMonkeyGames
ZephB wrote: Sat May 02, 2020 4:44 pm
JuanjoSalvador wrote: Sat May 02, 2020 12:06 pm
ZephB wrote: Sat May 02, 2020 12:22 am Should I draw the tilemap myself, would it be easier for me to test collisions?
Depending of the complexity of your tileset, but I would say no. Can you provide a .love file or something we can see?
Actually I have found the perfect solution. The cartographer library! It is capable of doing the same thing as what pico-8 is capable, it's really great. I've had somme issues so I created my own function in cartographer that allow me to quickly put a map, a tile_number and a property and that returns true or false, exactly like fget in pico-8. I'm really happy with it. This is what I added :

Code: Select all

function pget(map,gid,propertyName)
    local prespect
	if gid == false or gid == nil then
		prespect = false
		return false
	else
		prespect = map:getTileProperty(gid,propertyName)
		if prespect then
			return true
		else
			return false
		end
	end
end
Could you please give an example of how to use this?