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

Author Topic: Re-using sf::Image?  (Read 1649 times)

0 Members and 1 Guest are viewing this topic.

chris67

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re-using sf::Image?
« on: January 06, 2010, 02:17:59 am »
Is it safe to use the same sf::Image variable for more then one bitmap?

If I do this for instance:

Code: [Select]

sf::Image bitmap;
sf::Sprite sprite;

bitmap.LoadFromFile( "bitmap1.bmp" );

sprite.SetImage( bitmap );

App.Draw( sprite );

// and then do this

bitmap.LoadFromFile( "bitmap2.bmp" );

sprite.SetImage( bitmap ); // do I need to do this again?

App.Draw( sprite );


Is this safe or will I get a memory leak somewhere?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re-using sf::Image?
« Reply #1 on: January 06, 2010, 08:25:25 am »
It's perfectly fine, but the second time you'll have to manually change the subrect of the sprite so that it matches the new size of the image (it is done automatically only the first time).
Laurent Gomila - SFML developer