views:

25

answers:

1

Hi

I have a bitmapdata object that is filled with n rectangles of a width of 1 pixel and of varying heights.

I want to run through a loop and remove the old rectangle and replace it with a different one.

Should I do something like reset the each bitmap column of pixels to a background color and then add the rect i want?

for(i:int=0;i<bitmapdata.width;++i)

{
   (for var j:int=0;j<bitmapdata.height;j++)
{
  bitmapdata.setPixel(i,j,0x000000)
}

bitmapdata.fillrect(my new rect,0xffffff)


}
A: 

Well, I notice that you're using fillRect for something, why not use it for everything? Just fillRect the column in question, and then do another fillRect from the bottom up to make the new rectangle.

I'm not sure if that's the fastest way to do it, but you could try copyPixels, which I've heard is very fast. My suggestion for using this without any pain whatsoever is to assemble a bitmap that goes from having a column with 0px height to full height, and when you need a column of X height, copy from the pre-made bitmap at column X, and copy it to column Y on the original "bunch of bars" image.

Hope it helps. Post comments and I'll try to clarify in the answer, if need be.

31eee384