Header image

Collision Tests

December 19th, 2007 | Posted by lars in Actionscript | Experiments | Flash 9

As you noticed, I’m building a small arcarde shooter in AS3 besides my daily work. It started as a small test and got me ;). In my previous post I used getObectsUnderPoint for a hittest between the shot and the enemyclips, this works fine if you don’t need a collision reaction and the clips travel at a moderade speed. Now I wanted to integrate a collision detection and reaction for the enemies and made use of some nice scripts I found out there:

A shape-based collision detection for bitmaps by Grant Skinner, since the third parameter in hitTestPoint(x:Number, y:Number, shapeFlag:Boolean) only works for vectorimages and I’m using bitmaps as graphics. A Proximity Manager. This small class comes really handy and the principle is so simple. The proximity manager splits the stage into grids and stores for every sprite in which grid they are. So you don’t need to test every sprite against all other sprites, instead you just say: “Give me all neighbours of that sprite”, which saves a lot of loops.

So I had the tools for a nice collision detection, for the collision reaction I converted a simple snooker algorithm to AS3: Snooker Balls. Watch the result:

Move your mouse over me!

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

4 Responses



Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">