topical media & game development
lib-flex-animation-code-01-GridCollision-Ball.ax
lib-flex-animation-code-01-GridCollision-Ball.ax
(swf
)
[ flash
]
flex
package
{
import flash.display.Sprite;
public class @ax-lib-flex-animation-code-01-GridCollision-Ball extends Sprite
{
private var _color:uint;
private var _radius:Number;
private var _vx:Number = 0;
private var _vy:Number = 0;
public function @ax-lib-flex-animation-code-01-GridCollision-Ball(radius:Number, color:uint = 0xffffff)
{
_radius = radius;
_color = color;
draw();
}
private function draw():void
{
// draw a circle with a dot in the center
graphics.clear();
graphics.lineStyle(0);
graphics.beginFill(_color, 1);
graphics.drawCircle(0, 0, _radius);
graphics.endFill();
graphics.drawCircle(0, 0, 1);
}
public function update():void
{
// add velocity to position
x += _vx;
y += _vy;
}
public function set color(value:uint):void
{
_color = value;
draw();
}
public function get color():uint
{
return _color;
}
public function set radius(value:Number):void
{
_radius = value;
draw();
}
public function get radius():Number
{
return _radius;
}
public function set vx(value:Number):void
{
_vx = value;
}
public function get vx():Number
{
return _vx;
}
public function set vy(value:Number):void
{
_vy = value;
}
public function get vy():Number
{
return _vy;
}
}}
(C) Æliens
18/6/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.