bitmapFill transparancy

Hey all,

Im attempting to create my game graphics using bitmapfill…

From the Loader instance…


[LEFT]var img:Bitmap = e.target.content as Bitmap;
var bd:BitmapData = new BitmapData(img.width, img.height);
bd.draw(img);[/LEFT]
 
 
[LEFT]_grassSprite = new Sprite();
_grassSprite.graphics.beginBitmapFill(bd);
_grassSprite.graphics.drawRect(-(_width/2), -(_height/2), _width, img.height);
_grassSprite.graphics.endFill();[/LEFT]
 
addChild(_grassSprite);
 

I am trying to load in a transparent gif (orginally it was a png and originally i tried to embed it) but none of these work. I cant get transparancy in my fill.

Is this even possible? Am i doing something wrong?

Any help would be great.

Thanks,

I just tried this and it works but it does not really address the loss of transparacy to begin with.

It looks through the image for the non alpha white pixels and converts them into full alpha… I think thats what its used for!

var img:Bitmap =  e.target.content as Bitmap;
var bd:BitmapData = new BitmapData(img.width, img.height);
**bd.threshold(bd, new Rectangle(0, 0, img.width, img.height), new Point(0, 0), "==", 0xFFFFFFFF, 0x00000000);  **
bd.draw(img);
 
_grassSprite = new Sprite();
_grassSprite.graphics.beginBitmapFill(bd);
_grassSprite.graphics.drawRect(-(_width/2), -(_height/2), _width, img.height);
_grassSprite.graphics.endFill();
 
addChild(_grassSprite);

Check out the BitmapData constructor documentation…

Ahh man im so stupid.

i been setting the width and height and completely neglected the transparent flag.

var bd:BitmapData = new BitmapData(img.width, img.height, true);

Thanks :smiley:

EDIT.

This dont work if you embed the image with metatag but it seems to work if you use a Loader() instance.

Strange eh?

Also make sure you set the background color - the fourth argument. It’s in ARGB format (“A” for alpha). It defaults to 0xFFFFFFFF which is solid white (100% alpha)… Try 0x00FFFFFF for transparent white (of course the color doesn’t really matter when the alpha is set to 0)…

[QUOTE=devonair;2357206]Also make sure you set the background color - the fourth argument. It’s in ARGB format (“A” for alpha). It defaults to 0xFFFFFFFF which is solid white (100% alpha)… Try 0x00FFFFFF for transparent white (of course the color doesn’t really matter when the alpha is set to 0)…[/QUOTE]
Just set it to 0 for transparent.

0 = 0x00000000 = transparent black.

True, but lazy as I am, I can’t bring myself to do that… I code all color hex values in all caps and 6 - 8 alphanumerics… Can’t help myself… of course you’re right though - it’s the same thing…

Haha, well that is more consistent.