This site is no longer active and is available for archival purposes only. Registration and login is disabled.

2D Collision with tiled map/object


2D Collision with tiled map/object

Postby yuenkokeith » Feb 21, 2012 @ 3:10pm

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
yuenkokeith
pm Member
 
Posts: 2
Joined: Oct 13, 2011 @ 5:21pm


Re: 2D Collision with tiled map/object

Postby edge » Jun 7, 2012 @ 11:53am

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: Select all






RECT r1 = ...;
RECT r2 = ...;
if (r1.top < r2.bottom && r2.top < r1.bottom && r1.right > r2.left && r2.right > r1.left)
{
    // objects overlap
}
6 lines; 1 keywds; 0 nums; 32 ops; 0 strs; 1 coms    Syntactic Coloring v0.4 - Dan East  


- Marcel
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Return to EDGELIB


Sort


Forum Description

Powerful and affordable C++ middleware solution covering true multi-platform 2D, 3D and network features for Apple iPhone, Windows Mobile, Symbian S60, UIQ, Linux and Windows desktop.

Moderator:

edge

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron