• Create Account

### #ActualBeerNutts

Posted 21 August 2012 - 12:25 PM

IMO, the easiest way to solve this is to don't even worry about classes. You can use basic C-style functions to load your images and return the pointers to them in a generic Utility.cpp file, like this:

// in Utility.h define this
SDL_Surface GetImage(std::string imageName);

// in Utility.cpp, do this
std::map<std::string, SDL_Surface*> ImageMap;

SDL_Surface *GetImage(std::string imageName)
{
// check if this image is in the map
if (ImageMap.find(imageName) == std::map::end) {
// load it once into the map
}
return ImageMap[imageName];
}

// Then, when you want to load an image, #include "Utility.h" and call
SDL_Surface *PlayerImage = GetImage("player.png");

You can put Utility into a Utility namespace if you want, but that's just another option.
Good Luck.

### #1BeerNutts

Posted 21 August 2012 - 12:23 PM

IMO, the easiest way to solve this is to don't even worry about classes. You can use basic C-style functions to load your images and return the pointers to them in a generic Utility.cpp file, like this:

// in Utility.h define this
SDL_Surface GetImage(std::string imageName);

// in Utility.cpp, do this
std::map<std::string, SDL_Surface*> ImageMap;

SDL_Surface *GetImage(std::string imageName)
{
// check if this image is in the map
if (ImageMap.find(imageName) == std::map::end) {
// load it once into the map