|
-
Problems with alpha
hello, I'm very new to AS3.0 and I have problems with alpha. The next code is from my animation class and its main purpose is draw frame to other bitmapdata object.
Code:
// Copy the frame from original BitmapData.
destBitmapTempData.copyPixels(bitmapData, rect, zeroPoint);
// Set the newly copied BitmapData to Bitmap.
modifiedBitmap.bitmapData = destBitmapTempData;
// Change alpha
modifiedBitmap.alpha = 0.5;
// Get Matrix from the modifiedBitmap.
matrix = modifiedBitmap.transform.matrix;
// Change it if necessary
if (flipHor)
{
matrix.scale( -1, 1);
matrix.translate(width, 0);
}
if (flipVer)
{
matrix.scale( 1, -1);
matrix.translate(0, height);
}
// Clear previous frame.
destBitmapData.fillRect(zeroRect, 0x00000000);
// Draw the new frame.
destBitmapData.draw(modifiedBitmap, matrix);
// Copy the new frame to canvas.
canvasBD.copyPixels(destBitmapData, zeroRect, position, null, null, true);
The thing is that when I use copyPixels, the frame loses its alpha value. For example if I do new bitmap object from destBitmapData and addChild it, then the alpha remains, but not when I use copyPixels 
The canvasBD is created:
Code:
canvasBD = new BitmapData(screenRect.width, screenRect.height, true, 0x00FFFFFF);
Any ideas how do I get alpha remain to that frame?
Last edited by kadaAS3; 12-01-2008 at 06:16 AM.
Reason: wrong topic
-
Developer
Interesting, why have you set the fill colour for the bitmapdata as light blue? You should set it to white 0xFFFFFF really...
-
hmm, fill colour should be white and completely transparent first 00 hexs are for alpha and last 6 are for color and therefore 0x00FFFFFF should be completely white transparent or am I mistaken?
-
Developer
Have you tried changing it to 0xFFFFFFFF?
-
Senior Member
0xFFFFFFFF is white, and opaque. You had it right the first time.
I'm sure you've checked this, but the only advice I can give right this second is to make sure that when you declare both bitmapData objects, that you set the last/second last(?) parameter to true (alpha)...check the constructor for it, and you'll know what I mean.
P.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
yep, both bitmapData objects are:
Code:
this.destBitmapData = new BitmapData(frameWidth, frameHeight, true);
this.destBitmapTempData = new BitmapData(frameWidth, frameHeight, true);
And as I said before, the funny thing is if I do:
Code:
// Draw the new frame.
destBitmapData.draw(modifiedBitmap, matrix);
// This works, alpha remains.
modifiedBitmap.bitmapData = destBitmapData;
Game.game.addChild(modfiedBitmap);
// and this doesn't, no more alpha.
canvasBD.copyPixels(destBitmapData, zeroRect, position, null, null, true);
So if I don't copyPixels and I just add it to child, then it works as it should, so one fix would be that I make Bitmap object for every objects, add them to child and modify their bitmapData objects if necessary.
But the thing is that I would like to use one bitmap object as a canvas for the game and all the graphics are copied using copyPixels to that rather than have a multiple bitmaps and therefore multiple childs to deal with. Not sure if this a great way to do things though
-
Senior Member
It sure is (I think)...the draw() method is WAY slower than copyPixels()
Well, I'll have a look into it tonight, but I'm using as2...then again, the BitmapData class barely changed.
What's zeroRect, and those nulls, and what's canvasBD ?
As far as I see with the nulls, that could be your problem. If I'm right (I don't have Flash at the moment), you need to pass the Alpha channel bitmap? In fact, (even though that shouldn't be your problem), try passing the same bitmap for the alpha channel. At first I was just going to say you need to pass new BitmapData(), new Rectangle() for the 2 nulls, but try doing the bitmap first.
This is really strange...
P.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
-
M.D.
can you post the fla?
maybe with test gfx.
-
I use FlashDevelop and Flex sdk 3 so I have only source code (.as files + assets), but yes, I can share the source code but it'll have to wait until my work day is finished.
-
I noticed that if the source image has already some transparency then it works, so I guess the problem is when you change alpha in code it doesn't copy that?
-
Funkalicious
Ermmm, copypixels() does exactly that, it copies the pixels and sticks it to the other bitmapdata. No fancy effects. That's why it's a lot faster then draw().
If you want to use transparancy you should use draw with a colortransform.
-
Senior Member
That's one of the things I hate about BitmapData's...only way to change it is to do the draw() method pointing to itself, and then applying the new matrix...
I still have no idea...hopefully I'll be able to see from your source code!
P.
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
 Originally Posted by TOdorus
Ermmm, copypixels() does exactly that, it copies the pixels and sticks it to the other bitmapdata. No fancy effects. That's why it's a lot faster then draw().
If you want to use transparancy you should use draw with a colortransform.
GREAT! colorTransform did it! Problem solved, maybe I should have talked about transparency and not alpha and this could have been solved a long time ago but hey thanks to everybody!
I promise to share my game when it's ready for you guys! It will be like Metroid style game but a lot simplier
-
Senior Member
But...are you planning to do this in real-time? BitmapData.draw() is really slooow...
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
Developer
It's not really slooow - it's just slower than bitmap rendering. It's no more slower than drawing with normal vectors.
-
Funkalicious
 Originally Posted by dVyper
It's no more slower than drawing with normal vectors.
Well that depends. A vector graphic takes more power to render when there are more vectors. A bitmap graphic takes more power to render when there are more pixels. That's kinda comparing pears and apples.
-
Well, I use draw method only for matrix and I could do some improvements to that but it's not that slow, not my computer at least. Works smooth in full-screen mode
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|