Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Delete Sprites and free surfaces  (Read 8306 times)

0 Members and 1 Guest are viewing this topic.

SirForce

  • Newbie
  • *
  • Posts: 7
    • View Profile
Delete Sprites and free surfaces
« on: November 21, 2008, 09:06:59 pm »
Hi everybody,

as you can see in the topic title I want to know some things.
First, when I draw a sprite with Window.Draw(Sprite) on my screen, is there also the possibility to delete this sprite (while the program ist running)?

And the other question is, when I used the SDL (I think as many SFML user did) I had to call SDL_FreeSurface(Sprite) at the end of my programm. afaik I don´t need such an function when I use the SFML. Am I right?

Thanks for your answers.

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Re: Delete Sprites and free surfaces
« Reply #1 on: November 21, 2008, 09:12:40 pm »
Quote from: "SirForce"
First, when I draw a sprite with Window.Draw(Sprite) on my screen, is there also the possibility to delete this sprite (while the program ist running)?

Just stop drawing the sprite to the screen. Literally, just stop calling Window's Draw member on the Sprite if you want it to not be visible anymore.
Code: [Select]
if (SpriteIsVisible) Window.Draw(Sprite);

Quote from: "SirForce"
And the other question is, when I used the SDL (I think as many SFML user did) I had to call SDL_FreeSurface(Sprite) at the end of my programm. afaik I don´t need such an function when I use the SFML. Am I right?

Resources in SFML are freed as soon as they go out of scope. There is no function you can call to free resources for you.
Code: [Select]
int main()
{
    // i and s are NOT in scope

    {
        // i and s are NOT in scope

        int        i;
        sf::Sprite s;

        // i and s are in scope

        {
            // i and s are in scope
        }

        // i and s are in scope
    }

    // i and s are NOT in scope
}

Note:
If you need to instance things, such as sprites, use a STL container.