SimpleButton By PNG With Opaque Background Color

Dear community,

I am new to openFl. I would like to implement a button with the SimpleButton class.

It is no problem for me to get the png bitmap loaded. But I also want to give it an opaque background color.

That does not work. The button remains semi-transparent.

I have tried anything. And uncle google wasn’t very helpful as well…

What am I doing wrong?

Kind regards
Arnim

        var bitmapData : BitmapData = Assets.getBitmapData( "assets/close_button.png" );

        var bitmapUp : Bitmap = new Bitmap( bitmapData );

        bitmapUp.opaqueBackground = 0x29792f;
       //  bitmapUp.cacheAsBitmap = true;

        returnButton.upState = bitmapUp;

        var bitmapDown : Bitmap = new Bitmap( bitmapData );
        bitmapDown.opaqueBackground = 0x29792f;
        // bitmapDown.cacheAsBitmap = true;

        returnButton.downState = bitmapDown;

        var bitmapOver: Bitmap = new Bitmap( bitmapData );
        bitmapOver.opaqueBackground = 0x29792f;
        // bitmapOver.cacheAsBitmap = true;

        returnButton.overState = bitmapOver;

        var bitmapHitTest : Bitmap = new Bitmap( bitmapData );
        bitmapHitTest.opaqueBackground = 0x29792f;
        // bitmapHitTest.cacheAsBitmap = true;

        returnButton.hitTestState = bitmapHitTest;
        
        return returnButton;

Fixed, thank you:

This will be in the next release. In the meantime, you could try patching your copy, or putting your bitmap objects inside of a sprite, each, and setting a sprite.opaqueBackground

Ah, I see.

I already have found a work around.

I have inserted a Sprite instead of a Bitmap for each button state. First I added an opaque background as a child of the background. I have taken a rectangle shape for that.

Secondly I added the png so this lies on top of this construction.

For the time being it is ok. But on the long term, i consider this to be inefficent in concern of memory and cpu.

But your workaround is probably a little bit more elegent. So I try this at well.

Thank you for your answer, @Joshua.

Kind regards
Arnim