Permalink
Browse files

added new function replaceColor()

  • Loading branch information...
AdamAtomic committed Apr 30, 2011
1 parent 14e088d commit e486274446bdaba77e0f0ea4b28fd5e8f7769606
Showing with 30 additions and 0 deletions.
  1. +30 −0 org/flixel/FlxSprite.as
View
@@ -689,6 +689,36 @@ package org.flixel
}
}
+ public function replaceColor(Color:uint,NewColor:uint,FetchPositions:Boolean=false):Array
+ {
+ var positions:Array = null;
+ if(FetchPositions)
+ positions = new Array();
+
+ var row:uint = 0;
+ var column:uint;
+ var rows:uint = _pixels.height;
+ var columns:uint = _pixels.width;
+ while(row < rows)
+ {
+ column = 0;
+ while(column < columns)
+ {
+ if(_pixels.getPixel32(column,row) == Color)
+ {
+ _pixels.setPixel32(column,row,NewColor);
+ if(FetchPositions)
+ positions.push(new FlxPoint(column,row));
+ dirty = true;
+ }
+ column++;
+ }
+ row++;
+ }
+
+ return positions;
+ }
+
/**
* Set <code>pixels</code> to any <code>BitmapData</code> object.
* Automatically adjust graphic size and render helpers.

0 comments on commit e486274

Please sign in to comment.