Important Formulas in This Chapter

Lets review the important formulas introduced in this chapter.

Remove an out-of-bounds object:

 if(mc._x - mc._width / 2 > right     mc._x + mc._width / 2 < left     mc._y  mc._height / 2 > bottom     mc._y + mc._height / 2 < top) {       mc.removeMovieClip(); } 

Regenerate an out-of-bounds object:

 if(mc._x - mc._width / 2 > right     mc._x + mc._width / 2 < left     mc._y  mc._height / 2 > bottom     mc._y + mc._height / 2 < top) {       // reset mc position and velocity. } 

Screen wrapping for an out-of-bounds object:

 if(mc._x - mc._width / 2 > right) {    mc._x = left - mc._width / 2; } else if(mc._x + mc._width / 2 < left) {    mc._x = right + mc._width / 2; } if(mc._y  mc._height / 2 > bottom) {    mc._y = top  mc._height / 2; } else if(mc._y + mc._height / 2 < top) {    mc._y = bottom + mc._height / 2; } 

Apply friction (the correct way):

 speed = Math.sqrt(vx * vx + vy * vy); angle = Math.atan2(vy, vx); if(speed > friction) {    speed -= friction; } else {    speed = 0; } vx = Math.cos(angle) * speed; vy = Math.sin(angle) * speed; 

Apply friction (the easy way):

 vx *= friction; vy *= friction; 


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