Hey, y'all:
In my GUI, I want a sprite to appear when the user clicks a button. Now, I've tried doing this:
//sprite and surface declared globally
function HelloButton_OnClick(GUIControl *control, MouseButton button)
{
sprite = DynamicSprite.CreateFromExistingSprite(301); //Background sprite
surface = sprite.GetDrawingSurface();
surface.DrawImage(6 + 30*numSymbols, 6, HelloButton.Graphic);
surface.Release();
}
However, when I click the Hello button, nothing appears. Is there something obvious I'm not doing right?
Yes, you're forgetting to assign the sprite to be displayed.
// ...
surface.Release();
btnButtontouse.NormalGraphic = sprite.Graphic;
BTW, only the DynamicSprite has to be declared globally in this instance. The DrawingSurface is destroyed when you call surface.Release(). ;)
And by destroyed I do of course mean the script object is destroyed. The bitmap is then applied permanently as the DynamicSprite.Graphic.
Ah, thanks! See, I saw that in the documentation, but I didn't want to use a button. Turns out I can assign the sprite's graphic to gui backgrounds, too.
Yes, the background graphic will work fine as well as you've said. Glad you got it sorted! ;)