Important Formulas in This Chapter

Its time to review the two important formulas presented in this chapter.

Distance-based collision detection:

 // starting with mcA and mcB var dx:Number = mcB._x  mcA._x; var dy:Number = mcB._y  mcA._y; var dist:Number = Math.sqrt(dx*dx+dy*dy); if(dist < mcA._width / 2 + mcB._width / 2) {       // handle collision } 

Multiple-object collision detection:

 var numObjects:Number = 10; // for example for(var i:Number = 0; i<numObjects-1; i++) {       // evaluate reference using variable i. For example:      var objectA = this["object" + i];       for(var j:Number = i+1; j<numObjects;j++)      {             // evaluate reference using j. For example:             var objectB = this["object" + j];             // perform collision detection             // between objectA and objectB      } } 


Foundation ActionScript. Animation. Making Things Move
Foundation Actionscript 3.0 Animation: Making Things Move!
ISBN: 1590597915
EAN: 2147483647
Year: 2005
Pages: 137
Authors: Keith Peters

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net