DrYoshiyahu
678 posts
|
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?
|
BigJM
468 posts
|
You have a different bitmap on the stage than the one you’re modifying.
|
DrYoshiyahu
678 posts
|
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
|
vesperbot
1848 posts
|
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 ;)
|
DrYoshiyahu
678 posts
|
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.)
|
vesperbot
1848 posts
|
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().
|
DrYoshiyahu
678 posts
|
That parameter is true by default but never the less, it works now. :P
|
vesperbot
1848 posts
|
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.
|