Beginbitmapfill and transparency

Hi, I’m currently working on a game that has destructible terrain (a la Worms), and I’m struggling to find a good solution.

I initially had a solution that had a BitmapData object with an alpha-solid color, that would fill in a space dynamically created with points\line-to on a MC.

I was then able to remove sections by using fillrect with a transparent color.


// first solution to fill land
var bmpd:BitmapData = new BitmapData(550,400,true,0xff336600);
..
..
beginBitmapFill(bmpd, matrix, repeat, smoothing);

// solution to remove pixels
myRect= new Rectangle(xcoord,ycoord, random(45)+20, random(45)+20);
bmpd.fillRect(myRect,0x00FFFFFF);

This was fine, however I wanted to use a 256x256 texture to fill the landscape rather than a color. So I came up with the following:

 
// 2nd solution to fill land w/ texture
var bgBMP:BitmapData = BitmapData.loadBitmap("texture1");
..
..
beginBitmapFill(bgBMP);

Now the problem with the 2nd solution is twofold.

  1. when land is “destroyed” via fillrect or setpixel, the resulting pixels are white (even when using 0x00FFFFFF). Can you add an alpha channel to a BitmapData that is loaded?

  2. when pixels are removed from a specific _x and _y, they are repeated throughout the landscape. I suppose this is because the texture is 256x256, and has to be repeatedly copied to fill the landscape.

Does anyone have any advice? I even tried mapping each pixel to an array and using setpixel (couldn’t get copypixels to work) to copy the texture to the landscape, but that was very resource intensive. Maybe i should just create static landscapes and somehow mask transparencies… but that doesn’t seem as neat.

Thanks!

// first post

PT 1.
If you cannot directly work on loaded bitmap for transparencies. Try copying pixels to other bimapdata with transparent flag on

PT 2.
I think copy pixel should work fine… if not try using .draw method to copy your source bitmap texture on each tile mc…

// Welcome on Board :slight_smile: