Skip to content

Commit

Permalink
Change color of rings dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
j3k0 committed Apr 13, 2015
1 parent a16e365 commit 0ed9c07
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/starling/display/Ring.as
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ package starling.display
private var _innerRadius:Number;
private var _outerRadius:Number;
private var _outerRadius2:Number;
private var _polygons:Vector.<Poly4>;

public function get innerRadius():Number { return _innerRadius; }
public function get outerRadius():Number { return _outerRadius; }

public function Ring(innerRadius:Number, outerRadius:Number, color:uint=0xffffff, premultipliedAlpha:Boolean=true)
{
_polygons = new Vector.<Poly4>;
_innerRadius = innerRadius;
_outerRadius = outerRadius;
_outerRadius2 = outerRadius * outerRadius;
Expand All @@ -41,7 +43,7 @@ package starling.display
var p1:Point = new Point();
var nParts:int = Math.max(Math.round(outerRadius * 1.0), 8);
var angle:Number = 0;
for (var i:int = 0; i <= nParts; ++i) {
for (var i:int = 0; i < nParts; ++i) {
var a0:Number = (i + 0.0) * 2.0 * Math.PI / nParts;
var a1:Number = (i + 1.0) * 2.0 * Math.PI / nParts;
var ca0:Number = Math.cos(a0);
Expand All @@ -57,10 +59,17 @@ package starling.display
p1.x = outerRadius + ca1 * outerRadius;
p1.y = outerRadius + sa1 * outerRadius;
var q:Poly4 = new Poly4(c0, p0, c1, p1, color, premultipliedAlpha);
_polygons.push(q);
addChild(q);
}
}

public function set color(value:uint):void {
for (var i:int = 0; i < _polygons.length; ++i) {
_polygons[i].color = value;
}
}

public override function hitTest(localPoint:Point, forTouch:Boolean = false):DisplayObject {
// on a touch test, invisible or untouchable objects cause the test to fail
if (forTouch && (!visible || !touchable)) return null;
Expand Down

0 comments on commit 0ed9c07

Please sign in to comment.