In HaxeFlixel I do the following:
pixels is of the type
anotherSprite gets drawn on top of
someSprite. The problem is that when I give
anotherSprite an alpha this does not get translated when drawing the sprite on the bitmap. I can give the sprite an alpha of
0.1 but when drawing
someSprite after drawing
anotherSprite, the latter still appears in full alpha.
It’s worth noting that the transparency of
anotherSprite's image does not get lost.
Is there any way to fix this? I messed around with blend modes but nothing worked.
I’ve not familiar with HaxeFlixel, but since it piggy backs off of OpenFL, I’m going to assume this portion of the API is the same.
When using a BitmapData’s draw function, it does not automatically apply the source object’s color information such as tints or alpha transparency. That needs to be passed in from the source’s color transform. So try this instead:
someSprite.pixels.draw(anotherSprite.pixels, null, anotherSprite.transform.colorTransform);
You can read more about the parameters here.
Ah yes that works! But I actually asked a simplified version of my real problem, because I thought solving the simple version would solve Let me restate my problem. Though this might be a HaxeFlixel problem after all.
In HaxeFlixel I have a camera, and I want to draw the canvas of the camera to a sprite. So I do:
canvas is of the type
Sprite. But when drawing the canvas to the
pixels) the alpha gets lost. I can’t solve this with a colorTransform, because it’s the alpha of the individual sprites that get drawn onto the canvas, with each their own alpha.
Now it might be the case that the alpha is already lost in the canvas, and not necessarily when the canvas gets drawn onto the
bitmapData, but I’m not sure how I can be sure about that.
The only other thing I can think of is to make sure the BitmapData instance you’re using has the transparency flag turned on.
Otherwise, you’ll have to post some of your actual source code so we can get some idea of what the issue might be.