PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

2D Collision with tiled map/object

yuenkokeith · 21 Feb 2012, 14:10 UTC
Hi there,

Does anyone know how to tiled object and apply collision on them.
So a player can stand on top of it, or against a wall..etc

please give some example code of how to load them and handle it.

If possible, can edgelib release some tutorial/example code for this kind of stuff,
which is used frequently. It would be a great help to all new game maker.

Thank you very much.

regards,
keith
Hi,

Physics are a complicated subject, and there are several existing libraries available for free that do advanced collisions in 2D and 3D.

At the basics, what you need to know to test for is how objects collide. For two rectangles, you could use something like the following:
Code:
RECT r1 = ...;
RECT r2 = ...;
if (r1.top < r2.bottom && r2.top < r1.bottom && r1.right > r2.left && r2.right > r1.left)
{
// objects overlap
}


- Marcel