I need help creating an image manager. I have one, but calling something like
sprite.SetImage(Manager.RetrieveImage("gfx/player.tga"))
Will cause the program to crash.
Here is the source:
ImageManager.h
#include <map>
class ImageManager
{
private:
map<string, sf::Image> Data;
public:
sf::Image RetrieveImage(const string path);
bool LoadImage(string path);
int ImageCount();
} ;
ImageManager.cpp
#include "ImageManager.h"
sf::Image ImageManager::RetrieveImage(const string path)
{
if ( this->Data.find(path) != this->Data.end() )
{
return this->Data[path];
}
}
bool ImageManager::LoadImage(string path)
{
if ( this->Data.find(path) != this->Data.end() )
return true;
else
{
sf::Image IMGTemp;
if ( IMGTemp.LoadFromFile(path) )
{
this->Data[path] = IMGTemp;
return true;
}
else
return false;
}
}
int ImageManager::ImageCount()
{
return this->Data.size();
}