SFML community forums

Help => Graphics => Topic started by: chris67 on January 06, 2010, 02:17:59 am

Title: Re-using sf::Image?
Post by: chris67 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?
Title: Re-using sf::Image?
Post by: Laurent 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).