Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MoodyBlues on Sat 07/02/2009 06:04:12

Title: Making A Sprite Appear in a GUI Using DrawImage
Post by: MoodyBlues on Sat 07/02/2009 06:04:12
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?
Title: Re: Making A Sprite Appear in a GUI Using DrawImage
Post by: monkey0506 on Sat 07/02/2009 06:32:22
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.
Title: Re: Making A Sprite Appear in a GUI Using DrawImage
Post by: MoodyBlues on Sat 07/02/2009 07:29:53
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.
Title: Re: Making A Sprite Appear in a GUI Using DrawImage
Post by: monkey0506 on Sat 07/02/2009 08:39:36
Yes, the background graphic will work fine as well as you've said. Glad you got it sorted! ;)