Skip to content

Commit

Permalink
added new function replaceColor()
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamAtomic committed Apr 30, 2011
1 parent 14e088d commit e486274
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions org/flixel/FlxSprite.as
Expand Up @@ -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.
Expand Down

0 comments on commit e486274

Please sign in to comment.