CopyPixels isn't working (SOLVED)

Subscribe to CopyPixels isn't working (SOLVED) 8 posts

avatar for DrYoshiyahu DrYoshiyahu 678 posts
Flag Post

I have a BitmapData with my tilesheet, and a BitmapData that is my background.
But when I use copyPixels nothing happens. I’m not getting an error, the bitmap is blank. :(

public class Document extends MovieClip {
	public var worldHolder:MovieClip = new MovieClip();
	public var backgroundData:BitmapData;
	public var backgroundBitmap:Bitmap = new Bitmap(backgroundData);
	public var tilesheet:Tilesheet = new Tilesheet();
	public var bgPoint:Point;
	public var sourceRect:Rectangle;

	public function startGame():void {
		addChild(worldHolder);
		worldHolder.addChild(backgroundBitmap);
		createBackground();
	}

	public function createBackground():void {
		backgroundData = new BitmapData(roomWidth,roomHeight);
		backgroundBitmap = new Bitmap(backgroundData);
		bgPoint = new Point(maths);
		sourceRect = new Rectangle(col*50,row*50,50,50);
		backgroundData.copyPixels(tilesheet,sourceRect,bgPoint);
		trace(col,row2,bgPoint);
	}
}

My trace at the end is working. All the numbers are there.
I think that’s everything. Is there something I missed?

 
avatar for BigJM BigJM 468 posts
Flag Post

You have a different bitmap on the stage than the one you’re modifying.

 
avatar for DrYoshiyahu DrYoshiyahu 678 posts
Flag Post

Took me a while to understand what you meant but thankyou.
I was creating a new Bitmap AFTER I added it to the stage. :P

 
avatar for vesperbot vesperbot 1883 posts
Flag Post

You should not allocate backgroundBitmap within declaration, because you are re-allocating it in createBackground(). Or, drop “new Bitmap()” from that function, and just assign a proper BitmapData to existing backgroundBitmap.

edit: ninja’d, glad you managed to debug it ;)

 
avatar for DrYoshiyahu DrYoshiyahu 678 posts
Flag Post

New problem though. It has no transperancy. :(
I know that there’s parameters for alphaBitmapData, alphaPoint, and mergeAlpha, but I have no idea what to do with them.
(Setting them to null, null, and true does not work.)

 
avatar for vesperbot vesperbot 1883 posts
Flag Post

backgroundData = new BitmapData(roomWidth,roomHeight,true,0x00808080);

You need to manually specify a newly allocated BitmapData to have transparency. Then yes, use …null,null,true) when doing copyPixels().

 
avatar for DrYoshiyahu DrYoshiyahu 678 posts
Flag Post

That parameter is true by default but never the less, it works now. :P

 
avatar for vesperbot vesperbot 1883 posts
Flag Post

The default color is non-transparent (0xFFFFFFFF), this usually plays bad on anyone who’s creating bitmaps while not giving them default color. This one is fully transparent (first two zeroes are alpha value of 0), so your bitmap is fully transparent while nothing is drawn over it.