All Eyes Follow Target Rotation Tutorial

Published :
Author :
Adam Khoury
Learn a very efficient method of rotating multiple objects on stage. We are using Flash Actionsctipt 3.0 in this lesson which is suitable for online game programming and cool user interactive animations. var eyeArray:Array = [eye1, eye2, eye3, eye4, eye5, eye6]; stage.addEventListener(MouseEvent.MOUSE_MOVE, allEyesOnMe); function allEyesOnMe(event:MouseEvent):void { for(var eye:String in eyeArray){ var mousdiff_a:Number = mouseY - eyeArray[eye].y; var mousdiff_b:Number = mouseX - eyeArray[eye].x; var radians = Math.atan2(mousdiff_a,mousdiff_b); var degrees = radians / (Math.PI / 180); eyeArray[eye].rotation = degrees; } }