How can I delete DynamicSprite from my screen?

Started by fancasopedia, Sun 08/09/2019 10:55:45

Previous topic - Next topic

fancasopedia

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

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.

eri0o

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.

fancasopedia

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?

eri0o

The function you need is this: DynamicSprite.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.

fancasopedia

Quote from: eri0o on Sun 08/09/2019 14:14:09
The function you need is this: DynamicSprite.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.

Snarky

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.

morganw

Yes, try this.

Code: ags
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();
}

fancasopedia

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

SMF spam blocked by CleanTalk