Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-15-2008, 07:58 PM   #1
Registered User
Join Date: Mar 2008
Posts: 19
Default Collision Detection Kit

A short while ago 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.
- 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.
- 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. They aren't terribly pretty, but they make it clear just what this kit can do. 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 is of as much help to all of you as it has been for me!



Corey is offline   Reply With Quote
Old 05-15-2008, 08:09 PM   #2
Senior Member
Join Date: Apr 2007
Posts: 4,772

Hi Corey, welcome to the forums.

Looks pretty interesting, with some cool features. It will be interesting to see where you take it from here. Thanks for sharing and good work.
asf8 is offline   Reply With Quote
Old 05-21-2008, 06:43 PM   #3
Registered User
Join Date: Apr 2008
Posts: 173

Looks great, will give it a whirl!
fitz is offline   Reply With Quote
Old 05-21-2008, 08:08 PM   #4
Registered User
Join Date: Mar 2008
Posts: 19

Thanks, fitz!
Corey is offline   Reply With Quote
Old 05-21-2008, 10:21 PM   #5
Join Date: Jan 2005
Posts: 54

Hi Corey,

This is some amazing stuff, I think there is a lot of potential here. I was wondering if you would be willing to give out some of the source code for your examples, particularly the Video example. I've played around trying to replicate it but can't seem to get my head around it. PM me if you wish. Thanks.
skinnykid is offline   Reply With Quote
Old 05-22-2008, 12:17 AM   #6
Registered User
Join Date: Mar 2008
Posts: 19

Hey, skinnykid! I have received one or two requests like this, and I do plan on releasing the source code for the examples on my site. I hope to find the time to do that this weekend, at which point they'll be available both on my site and on Google Code.
Corey is offline   Reply With Quote
Old 05-22-2008, 12:49 AM   #7
Tomgupper's Avatar
Join Date: Dec 2003
Posts: 52
Send a message via ICQ to Tomgupper Send a message via MSN to Tomgupper

Hi Corey,
This is fantastic.

This is pretty much exactly the sort of thing I was looking for. I saw the gskinner variations ( and the AS3 port ) however they were fairly simple in nature, love the functionality that comes with this , esp. the angle of collision.

Will have to grab this when I get home from work and have a play.
You're only one drug away from liking techno.
Tomgupper is offline   Reply With Quote
Old 05-28-2008, 01:30 AM   #8
Registered User
Join Date: May 2008
Posts: 20

that looks awesome i will try that... thx soo much
Kingslayer is offline   Reply With Quote
Old 05-28-2008, 04:05 AM   #9
Super Moderator
ASWC's Avatar
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528

the example where you draw a line is actually buggy since some of the balls go through the line. There's a lot of tutorials out there for line rider type game that can show you how to fix that.
Super Duper!
ASWC is offline   Reply With Quote
Old 05-28-2008, 12:58 PM   #10
Registered User
Join Date: Mar 2008
Posts: 19

Absolutely, ASWC. I've been wanting to correct that example, it's just a matter of finding the time (and then remembering I wanted to do that). Hectic schedules and such. Thanks for pointing it out, though! Maybe I'll remember to take care of it now...
Corey is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Other ways of collision detection other than hitTestPoint/Object MarionC ActionScript 3.0 4 07-22-2008 04:45 AM
Collision detection ASWC ActionScript 2.0 3 12-30-2007 09:10 AM
Flash MX 2004 - Points Class (Collision detection pains) robtyketto ActionScript 1.0 (and below) 0 04-14-2007 12:34 AM
Collision Detection. rask ActionScript 2.0 0 01-30-2006 08:58 AM
Optimizations for Collision Detection IonRod ActionScript 2.0 0 12-24-2005 03:48 AM

All times are GMT. The time now is 11:18 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.