Transparency using Color Key

First off, hi everyone. I’ve been poking around OpenFL for quite some time now but I’ve finally joined the forums. I’m currently working on my own game framework on top of OpenFL 3.6. :slight_smile:

So I poked around a bit in the forums and API and haven’t come up with a conclusive answer: is there a way to make a particular color value transparent on a sprite/bitmapdata/etc. Is this something I would accomplish via a BlendMode or ColorTransform operation?

First, if you use BitmapData, be sure it supports transparency (that is the third argument after width and height when you create one)

Using bitmapData.setPixel32, not setPixel, allows a color with alpha. 0x88FF0000, for example, is semi-transparent red.

if you’re referring to the API, there should be alpha when you start fills or line styles

Be aware, though, using alpha on the entire object is cheaper, as it uses a hardware shader, rather than a software process

Thanks for the reply, but I don’t think I articulated myself well enough. What I meant before is that the image already has something like a background color and I want to make that show up as fully transparent. That background color is the color key you designate as transparent.

So, a chroma key or “green screen” effect? OpenFL doesn’t have built-in support for that, and I’m not aware of any libraries for it.

The easiest solution would be to draw to a bitmap and then manually alter the pixels. This wouldn’t be very efficient, though.

The efficient solution would be to use shaders, but those are going through changes at the moment, so you might want to hold off until the API settles down.

Ah, OK. Its probably more efficient to just import the images with straight transparency anyway, right?

If processing them beforehand is an option, definitely do that. Most image editors should have a filter for it.


That looks promising.

At any rate though, I’m planning to just load my images with transparency already in them. Seems like the simplest and most efficient way to proceed. Thanks for the suggestions.

Not sure if I should mark this solved or not.