Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: geork on Fri 28/01/2011 22:46:16

Title: Button does not change into sprite graphic!
Post by: geork on Fri 28/01/2011 22:46:16
Hey all!
  I'm trying to change a button's graphic to the graphic of a Dynamic Sprite within a function. I have read other posts, and tried to copy what they do, but strangely for me the button just turns up with a blank image. Here's the code:

// At the top of the Global Script
  DynamicSprite *s;

// Later on...
function bSave_OnClick(GUIControl *control, MouseButton button)
{
  s = DynamicSprite.CreateFromExistingSprite(31); //this is to test, I actually load another DynamicSprite's image
                                                                                // into this one...
  s.Resize(90, 60); //Optional, doesn't work with or without...
  bButton.NormalGraphic = s.Graphic;
  s.Delete();
  SaveGameSlot(btn, date); //these two are established elsewhere
  btn = 0;
  AfterSave(); //just does some business after the save
}

  I've even tried to reload an image into 's' and change the button's normal graphic in AfterSave() instead of bSave_OnClick, but no luck...
  Anyone have a solution?
   Thanks
Title: Re: Button does not change into sprite graphic!
Post by: monkey0506 on Fri 28/01/2011 23:07:40
You're deleting the sprite!

When you call DynamicSprite.Create you are creating a new sprite. When you call DynamicSprite.Delete you are deleting that sprite.

If you delete a file from your hard drive you can't very well expect to just keep using it.

You should only delete the sprite when you're done using it. For example, you're creating a new dynamic sprite every time the player clicks the bSave button, so you could add a check at the top of that function:

if (s != null) s.Delete();

But if you're deleting a sprite that is in-use by the button (bButton's normal graphic) then it's not going to work the way you want..
Title: Re: Button does not change into sprite graphic! (SOLVED)
Post by: geork on Fri 28/01/2011 23:15:32
 Thanks!
  It's working fine now. In the manual it always writes in big DELETE SPRITE ASAP!, which is why I always did it, now I finally get what it really means  ;D
  Thanks again!
Title: Re: Button does not change into sprite graphic!
Post by: monkey0506 on Fri 28/01/2011 23:58:09
Well, in this case "ASAP" means "As Soon As You Are Done Actually Using The Sprite" :P