From: Ernesto Corvi <erne...@on-core.com>
Date: Wed, 3 Dec 2008 15:03:42 -0800 (PST)
Local: Wed, Dec 3 2008 6:03 pm
Subject: Re: Strategies for collision detection.
Sorry I didn't answer earlier guys, been pretty busy at work.
This technique I'm going to describe works for background collision detection. Inter-sprite collision detection should be done by checking the sprite boundaries themselves. I'm also not going to post code, but give you a general idea and function names so you guys can look them up and craft something together yourselves. Say we want to create an arbitrary collision map. What we want, is to
When you're loading your level, you also create your collision array,
1) Load the image:
2) Get the image size:
3) Allocate our array for quick lookups and clear it:
4) Get access to the raw bits of the image
5) Build our collision map:
6) Release what we no longer need:
Now, whenever you need to see if you hit something, you call a routine
// TODO: check for boundaries here
return collisionMap[(y*width)+x];
}
And that's it. The actual detection part is what would be time
consuming and it's just a simple lookup at this point. If you have questions, feel free to ask. You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||