Petre Popescu
Petre Popescu

Reputation: 2002

AS3 Tint Bitmap

I have a spritesheet for a project I am working on and I need to be able to change the tint of the image so I can se space. The image has some simple texture on it but it will be displayed in 5 different colors. I attached an image to see exactly what I am talking about: http://i42.tinypic.com/29443l5.png

I tried to achieve my desired effect using this on the resulting sprite:

var c:ColorTransform = new ColorTransform();
c.color = 0xf30909;
transform.colorTransform = c;

But I get everything red, not as I want. I am building for AIR so the package fl.motion.Color can't be imported (or at least Flash Builder 4.5 does not have it). Any idea on how I can achieve the desired effect? Thanks.

Upvotes: 3

Views: 3615

Answers (2)

Jorjon
Jorjon

Reputation: 5434

Just for the sake of completeness...

public function Tint(display:DisplayObject, color:uint) {
    display.transform.colorTransform = new ColorTransform(color >> 16 & 0x0000FF / 255, color >> 8 & 0x0000FF / 255, color & 0x0000FF / 255);
}

Upvotes: 6

Staven
Staven

Reputation: 3165

The color property sets the offset, i.e. it makes the ColorTransform add the color value to your image. You probably want to use the Multiplier properties. See ColorTransform documentation.

Upvotes: 3

Related Questions