Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fancasopedia on Sun 08/09/2019 10:55:45

Title: How can I delete DynamicSprite from my screen?
Post by: fancasopedia on Sun 08/09/2019 10:55:45
Hello guys, I searched a lot but did not find a solution for my problem. It seems easy but somehow I'm stuck :)

Code (ags) Select

function Speak(this Character*, int iconNumber, String chardialog)
{
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(iconNumber, true);
sprite.Resize(75, 75);
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(10, 640, sprite.Graphic);
sprite.Delete();
surface.Release();
this.SayAt(10,680, 1200, chardialog);
}


After this function finished, the sprite doesn't go anywhere from the screen. 

Here is a example of what my code do= https://ibb.co/HPSnFGm

After dialog end,sprite doesn't go which I mentioned above. Also, when i use this function for other npc,the npc's icon showed up above the previous character's icon. I dont want to risk our game's future(memory leak etc.), so I had to ask you guys.
Title: Re: How can I delete DynamicSprite from my screen?
Post by: eri0o on Sun 08/09/2019 11:16:07
Once a Sprite is draw to any surface you can't remove from it, because it's no longer a sprite, instead it's now a bunch of pixels. If you wish to preserve any surface after drawing, instead, you need to copy those pixels elsewhere, the easiest way being creating a dynamic sprite that holds a copy of the pixels at the previous state.
Title: Re: How can I delete DynamicSprite from my screen?
Post by: fancasopedia on Sun 08/09/2019 11:30:01
Quote from: eri0o on Sun 08/09/2019 11:16:07
Once a Sprite is draw to any surface you can't remove from it, because it's no longer a sprite, instead it's now a bunch of pixels. If you wish to preserve any surface after drawing, instead, you need to copy those pixels elsewhere, the easiest way being creating a dynamic sprite that holds a copy of the pixels at the previous state.

Thank you :) Can you write a piece of code for my problem if you dont mind?
Title: Re: How can I delete DynamicSprite from my screen?
Post by: eri0o on Sun 08/09/2019 14:14:09
The function you need is this:  DynamicSprite.CreateFromBackground() (https://adventuregamestudio.github.io/ags-manual/DynamicSprite.html#createfrombackground). You need to store this Dynamic Sprite somewhere.

I can't write you a code because it's unclear what you are trying to do. :/ For instance, I can't even understand if the scope of the copy of background sprite needs to be on the function or globally in your case.
Title: Re: How can I delete DynamicSprite from my screen?
Post by: fancasopedia on Sun 08/09/2019 14:52:26
Quote from: eri0o on Sun 08/09/2019 14:14:09
The function you need is this:  DynamicSprite.CreateFromBackground() (https://adventuregamestudio.github.io/ags-manual/DynamicSprite.html#createfrombackground). You need to store this Dynamic Sprite somewhere.

I can't write you a code because it's unclear what you are trying to do. :/ For instance, I can't even understand if the scope of the copy of background sprite needs to be on the function or globally in your case.

According to talking character, icon's must be change globally at same position in screen. After character talk, the icon's area must look empty. i declared this function in my script. You just write by yourself  then I can transform it :)

Can I do tricks like declaring icons same as grey panel on screen? After speech is over, grey must be on screen, therefore it  can look empty maybe.
Title: Re: How can I delete DynamicSprite from my screen?
Post by: Snarky on Sun 08/09/2019 15:27:43
Usually if you want to display a DynamicSprite temporarily, you assign it as the Graphic of a room object or a GUI control (e.g. a Button), and show that. Or you can use a graphical Overlay. That way you can easily get rid of it when you no longer need it. Drawing onto the room background is something you'd usually only do if you're making a permanent change to the entire room.
Title: Re: How can I delete DynamicSprite from my screen?
Post by: morganw on Sun 08/09/2019 15:38:19
Yes, try this.

Code (ags) Select
function Speak(this Character*, int iconNumber, String chardialog)
{
  DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(iconNumber, true);
  sprite.Resize(75, 75);
  Overlay* icon = Overlay.CreateGraphical(10, 640, sprite.Graphic, true);
  this.SayAt(10, 680, 1200, chardialog);
  icon.Remove();
  sprite.Delete();
}
Title: Re: How can I delete DynamicSprite from my screen?
Post by: fancasopedia on Sun 08/09/2019 15:40:40
Quote from: Snarky on Sun 08/09/2019 15:27:43
Usually if you want to display a DynamicSprite temporarily, you assign it as the Graphic of a room object or a GUI control (e.g. a Button), and show that. Or you can use a graphical Overlay. That way you can easily get rid of it when you no longer need it. Drawing onto the room background is something you'd usually only do if you're making a permanent change to the entire room.

THANK YOU!  :-D :-D :-D :-D