Make a sprite disappear behind a transparent sprite?

  • I'm just wondering if it's possible to make a sprite get hidden behind a fully transparent sprite (or rectangle). The sprite should be able to be only partially hidden behind the transparent sprite, creating an effect like this:

    alt text

    Is there a way to do this? For C++ targets.

  • Hello,

    I'm unsure if you can do this without using a custom shader for it. I myself never used cusom shaders for HaxeFlixel and I dont think that there is much documentation on it. But in the sourcecode a shader is just typedef'ed to a openfl.display.Shader (and requires -Dnext). So you probably best off checking that out.

    A workaround for this is perhaps to copy the pixels of the background and make a new bitmap from that and use that instead of a transparent sprite. If your situation is always on the same place and does not need to be updated that much, this is perhaps the best solution.

    Also I've never used all available blend modes. But if I look at the invert one, it just might do the job. Perhaps you can check that out.

    Hopefully this helps you out a bit.

  • Quote: Blendmode ALPHA

    inline read onlyALPHA:BlendMode = '???'
    Applies the alpha value of each pixel of the display object to the background. This requires the blendMode property of the parent display object be set to openfl.display.BlendMode.LAYER.

    Not supported under GPU rendering.

    The last line makes me nerves for CPP targets, but you can try it.

  • Blendmode Substract says:

    Subtracts the values of the constituent colors in the display object from the values of the background color, applying a floor of 0. This setting is commonly used for animating a darkening dissolve between two objects.

    For example, if the display object has a pixel with an RGB value of 0xAA2233, and the background pixel has an RGB value of 0xDDA600, the resulting RGB value for the displayed pixel is 0x338400(because 0xDD - 0xAA = 0x33, 0xA6 - 0x22 = 0x84, and 0x00 - 0x33 < 0x00).

    If this works on the alpha channel aswell, then perhaps this one is better if ALPHA blends dont work on CPP

  • This HaxeFlixel tutorial on masking could help.

    I have actually tried blend modes myself. I used a transparent sprite, of course, but found no blend mode that uses the alpha of the top layer. Then I wondered if I could have a custom blend mode so I researched shaders as HaxeFlixel supports it. According to what I have read, shaders do not know nothing at all about other sprites. So, yeah, both didn't work, at least for me.

  • Well, too bad the blendmodes don't work. a lot of them do specify: "Not supported under GPU rendering."... Anyways the link of the tutorial looks promising. Probably the best solution.

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.