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
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..
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!
Well, in this case "ASAP" means "As Soon As You Are Done Actually Using The Sprite" :P