SFML community forums
Help => Graphics => Topic started by: Deftwun on October 04, 2011, 04:46:42 am
-
Is their a way to release an sf::image without deleting it. Also without modifying the sfml source..
I'm trying to put together a resource manager that can cache certain resources depending on the game state and quickly load and release them. but I have my image resource inherit from sf::image and dont really see a public function that would allow that.
the only thing I can think of would be to have a sf::image member in my resource class like so...
class myImageResource{
private:
sf::image * mySFImage;
std::string myFileName;
public:
myImageResource(std::string theFileName):
myFileName(theFileName)
mySFImage(new sf::image) //<--- not really sure if thats legal but you get the idea...
void Load(){
mySFImage->LoadFromFile(mFileName
}
void Release(){
delete mySFImage;
}
};
this is just an example but it already feels hacky and unsafe. I dont want to have to create and delete the sf::image every time ya know? I really want the resource to inherit from sf::image to make things streamlined.
any thoughts, comments?
-
PS : I think I may possibly be over engineering this :)
-
image.Create(0,0);
might work. If not, then image.Create(1,1);
-
Why would you want to keep an empty sf::Image instance? If you want to release the image, it seems more natural to completely get rid of the whole object.
image.Create(0,0);
I prefer this solution:
image = sf::Image();
But it's still a "hack".