topical media & game development
animation-ch03-Oval.ax
animation-ch03-Oval.ax
[swf]
[flash]
flex
package
{
import flash.display.Sprite;
import flash.events.Event;
public class @ax-animation-ch03-Oval extends Sprite {
private var ball:animation_ch03_Ball;
private var angle:Number = 0;
private var centerX:Number = 200;
private var centerY:Number = 200;
private var radiusX:Number = 200;
private var radiusY:Number = 100;
private var speed:Number = .1;
public function @ax-animation-ch03-Oval() {
init();
}
init(s)
private function init():void {
ball = new animation_ch03_Ball();
addChild(ball);
ball.x = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
frame(s)
public function onEnterFrame(event:Event):void {
// the book seems to make a mistake here
// ball.x = centerX + Math.sin(angle) * radiusX;
// ball.y = centerY + Math.cos(angle) * radiusY;
ball.x = centerX + Math.cos(angle) * radiusX;
ball.y = centerY + Math.sin(angle) * radiusY;
angle += speed;
}
}
}
(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.