I'm on my way with a tiled based game. I have correctly implemented scrolling, position handling etc.
I have (before) had a simple collision system that is a really bad one, and now I'm going to switch from simple x and y checks to AABB.
The real problem isn't really about AABB itself, since I've made a simple application demonstrating the technique - it works like intended. This is for singular, independent objects that is static.
Since I know the technique and how to resolve collisions correctly I wanna apply this AABB technique to my tile world. It is now the real problem (or question?) arises.
Since the world is built on tiles and the world's objects is built together to a world, how would I implement the AABB? Before it was only for single static objects, now for a whole world. Is it possible to create a single world static object or are there any better idea out there?
Should I create a single box for every single tile in the world? It doesn't sound well, but how should I fight this problem down?
Any help is appreciated!
Comments to Nick's answer:
Considering what you've said about how you previously had a "simple collision system that was a really bad one", I assume you want the latter.
That's correct. The previous collision system made my character get stuck in tiles and it wasn't working properly.
So you can see how it will haphazardly overlay your four tiles. Your AABB for the object then is a rect with x=7, y=10, w=12, h=15. Let's say this is your only obstacle in the world.
I understand, I think. Does this necessarily mean I have to create a single AABB for every tile?
You can see that due to his width and height, he now overlaps the top left of your obstacle at {7,10}. So resolve the collision. That's all there is to it.
Yep, that part I understand. For now, the world is built from a single 2D array, but is it really efficient to create an AABB for every obstacle?
Oh, I think it does not really matter if I only loop through the obstacles and tiles in the area where the player is..