Making A Sprite Appear in a GUI Using DrawImage

Started by MoodyBlues, Sat 07/02/2009 06:04:12

Previous topic - Next topic

MoodyBlues

Hey, y'all:

In my GUI, I want a sprite to appear when the user clicks a button.  Now, I've tried doing this:

Code: ags

//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?
Atapi - A Fantasy Adventure
Now available!: http://www.afwcon.org/

monkey0506

Yes, you're forgetting to assign the sprite to be displayed.

Code: ags
  // ...
  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.

MoodyBlues

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.
Atapi - A Fantasy Adventure
Now available!: http://www.afwcon.org/

monkey0506

Yes, the background graphic will work fine as well as you've said. Glad you got it sorted! ;)

SMF spam blocked by CleanTalk