simple/annoying question - button graphics

Started by wynni2, Thu 13/04/2017 21:13:56

Previous topic - Next topic

wynni2

Hi all -

This is a very simple but annoying issue.  I'm trying to remove the default "button" graphics from the buttons on a GUI and replace them with a transparent sprite that has the button's description on it.  Here is the code I'm using:

Code: ags

            DynamicSprite *bfast = DynamicSprite.Create(btnFast.Width, btnFast.Height); 
            DrawingSurface *dfast = bfast.GetDrawingSurface(); 
            dfast.Clear(); 
            dfast.DrawingColor = player.SpeechColor; 
            dfast.DrawString(0, 0, Game.NormalFont, "Fast"); 
            dfast.Release();
            btnFast.NormalGraphic = bfast.Graphic;


That code is repeated for each of the buttons, however it doesn't work.  The button either retains its original default graphic or (if I delete the button text) it is completely invisible (the GUI and buttons are still enabled correctly, just invisible).  This seems like a problem with a simple solution, but I'm not sure why my code isn't working.

Thanks.

dayowlron

I havent worked a lot with Dynamic Sprites or Drawing Surfaces yet, however I can suggest one thing to try.

Declare the bfast outside of the function where this is running. I have a feeling you are creating the bfast sprite and when it finishes the code the bfast sprite is going away and therefore the btnfast graphic is reverting back to the basic.

at the top of the module
Code: ags

    DynamicSprite *bfast;


then change line 1 to be:
Code: ags

    bfast = DynamicSprite.Create(btnFast.Width, btnFast.Height);
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

wynni2

That did it.  Simple, as I expected.

Thanks.

SMF spam blocked by CleanTalk