Results 1 to 15 of 64
Thread: Collision Detection Kit
May 15th, 2008, 01:16 PM #1
Collision Detection Kit
Recently I had a need for shape-based collision detection and decided to write up a class to handle it. As the class developed, I discovered other things that would be nice to have but weren't available, so I worked it out and added the functionality to my class.
Long story short, it developed into a small package of code I call the Collision Detection Kit. It's been so useful for me that I've decided to put it under an MIT license and share it with all of you.
It uses bitmapdata to find overlapping pixels of display objects. Not a new idea, I realize, but I wrote mine out from scratch anyways to handle things the way I needed them handled. This allowed me to figure out a few other nifty features that I include in the kit. Here are the big ones that me and my beta testers/coworkers have been loving:
- Set an alpha threshold so that any pixels on a display object below that alpha won't be checked for collisions.
- Exclude colors and color ranges from collision detection.
- The kit can approximate the angle of a collision, allowing you to keep your physics convincing when colliding with odd/organic shapes. It took awhile to figure out a good way of doing this. It's my favorite part of the kit.
- Gives you the pixels that overlap in a collision in stage coordinates, making it easier for you to adjust positions or apply off-center rotation convincingly.
- The kit takes nesting into account, so it doesn't matter where your display objects are on the display list.
- Takes transforms into account for individual instances, so things like scaling, rotating, and performing color transforms on your objects are no problem. This includes transformation made to any parent containers!
- Can be used with display objects on or off the display list. Works great alongside blitting engines.
- Works with all display objects: MovieClips, Sprites, TextFields (very cool), FLVs, etc.
I've created pre-compiled examples to show off these features and give you a better idea of what this package is capable of doing. I also have all classes documented, available online and for download (includes some rudimentary source code examples).
Feedback is welcomed! I don't have a discussion list for this yet, but plan on adding that or a forum later this evening (via Google Code). In the meanwhile, post any questions you might have here. I hope this can help some people out, as it's helped me a ton!
A new version of the CDK (v1.5) is now available! Links have been updated. I'm thrilled that the CDK has been so useful to so many devs, and I'm glad to finally be pushing out this update based on user feedback. Enjoy!
Last edited by skineh; June 6th, 2009 at 04:21 PM.
May 15th, 2008, 01:51 PM #2
Wow, nice work bud, I'm impressed. Nasty graphics, but a superb little collision engine
Thanks for sharing it.
May 15th, 2008, 01:56 PM #3
May 15th, 2008, 09:29 PM #4
May 16th, 2008, 03:22 AM #5204Registered User
Nice work dude ... Much appreciated
May 16th, 2008, 09:37 AM #6
May 20th, 2008, 07:15 PM #747BEŞİKTAŞ
thanks.i m use itTUNCAYS
May 21st, 2008, 06:40 AM #824Registered User
Will check it out at once.
May 21st, 2008, 06:50 AM #91,532I make half sense
May 21st, 2008, 12:12 PM #10
Hahaha, thanks guys! My babies are in high demand, so might have to put you in a queue. Really, though, glad to hear you all like it! It's been a busy week for me, but I'm going to get a forum put up for it on Google Code soon in case anyone has any questions and so on.
May 21st, 2008, 12:17 PM #11
That's amazing!COLOURlovers | Member #2 of the kirupa XBox 360 Club
"I think most people would agree that your computer breaking is a Christmas miracle." ~shane-c to Timmytots
May 21st, 2008, 01:51 PM #12
I'm surprised this hasn't had even more feedback actually.
It's great. The only thing I would say so far is find ways to optimise performance, for the amount of objects that were active, it seemed a TAD cpu heavy.
When I've got time, I'm going to play around with it, and find ways to implement it.
May 21st, 2008, 02:11 PM #13
Thanks for the feedback Esherido, rumblesushi.
Yea, rumblesushi, I agree there's probably room for optimization. It went through several phases of redesign along the way, and a few cheap tricks were incorporated into some of the math to get some small increases in performance. Still, there's always room for improvement! If you end up doing anything with the package (especially if you rewrite it and get it to perform faster), I'd love to hear about it!
I should note that performance will also depend heavily on what features you're implementing. Color exclusion is the most CPU-intensive, as the bitmapdata samples taken for comparison have to perform significantly more checks against their pixel information to see if they fall under the color ranges a user has specified.
May 21st, 2008, 04:45 PM #14213Registered User
It wouldn't hurt to include some source code examples of how to use it, like for the examples or something.
More specifically examples showing how the various features that it has are useful for shaped based collision detection.
May 21st, 2008, 04:51 PM #15