topical media & game development
animation-ch06-Friction2.ax
animation-ch06-Friction2.ax
[swf]
[flash]
flex
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class @ax-animation-ch06-Friction2 extends Sprite
{
private var ball:animation_ch06_Ball;
private var vx:Number = 0;
private var vy:Number = 0;
private var friction:Number = 0.9;
public function @ax-animation-ch06-Friction2()
{
init();
}
private function init():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
ball = new animation_ch06_Ball();
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
vx = Math.random() * 10 - 5;
vy = Math.random() * 10 - 5;
addChild(ball);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
vx *= friction;
vy *= friction;
ball.x += vx;
ball.y += vy;
}
}
}
(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.