topical media & game development
animation-ch10-Rotate3.ax
animation-ch10-Rotate3.ax
[swf]
[flash]
flex
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
public class @ax-animation-ch10-Rotate3 extends Sprite
{
private var balls:Array;
private var numBalls:uint = 10;
private var vr:Number = .05;
public function @ax-animation-ch10-Rotate3()
{
init();
}
init(s)
private function init():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
balls = new Array();
for(var i:uint = 0; i < numBalls; i++)
{
var ball:animation_ch10_Ball = new animation_ch10_Ball();
balls.push(ball);
addChild(ball);
ball.x = Math.random() * stage.stageWidth;
ball.y = Math.random() * stage.stageHeight;
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
frame(s)
private function onEnterFrame(event:Event):void
{
var angle:Number = (mouseX - stage.stageWidth / 2) * .001;
var cos:Number = Math.cos(angle);
var sin:Number = Math.sin(angle);
for(var i:uint = 0; i < numBalls; i++)
{
var ball:animation_ch10_Ball = balls[i];
var x1:Number = ball.x - stage.stageWidth / 2;
var y1:Number = ball.y - stage.stageHeight / 2;
var x2:Number = cos * x1 - sin * y1;
var y2:Number = cos * y1 + sin * x1;
ball.x = stage.stageWidth / 2 + x2;
ball.y = stage.stageHeight / 2 + y2;
}
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.