topical media & game development
animation-ch14-Segment.ax
animation-ch14-Segment.ax
[swf]
[flash]
flex
package
{
import flash.display.Sprite;
import flash.geom.Point;
public class @ax-animation-ch14-Segment extends Sprite
{
private var color:uint;
private var segmentWidth:Number;
private var segmentHeight:Number;
public var vx:Number = 0;
public var vy:Number = 0;
public function @ax-animation-ch14-Segment(segmentWidth:Number, segmentHeight:Number, color:uint = 0xffffff)
{
this.segmentWidth = segmentWidth;
this.segmentHeight = segmentHeight;
this.color = color;
init();
}
public function init():void
{
// draw the segment itself
graphics.lineStyle(0);
graphics.beginFill(color);
graphics.drawRoundRect(-segmentHeight / 2,
-segmentHeight / 2,
segmentWidth + segmentHeight,
segmentHeight,
segmentHeight,
segmentHeight);
graphics.endFill();
// draw the two "pins"
graphics.drawCircle(0, 0, 2);
graphics.drawCircle(segmentWidth, 0, 2);
}
public function getPin():Point
{
var angle:Number = rotation * Math.PI / 180;
var xPos:Number = x + Math.cos(angle) * segmentWidth;
var yPos:Number = y + Math.sin(angle) * segmentWidth;
return new Point(xPos, yPos);
}
}
}
(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.