Hey guys, I'm pretty new to the C++ / SFML scene and was wanting some advice from more experienced users on how to handle this. I'm starting by writing a simple Tetris like game, and one thing i'm particularly stumped on is the way to handle images. I've set up a class that manages images so that they're not loaded more than once by storing them in a map. The problem, though, lies in where I should declare the instance of this imagecache in my code.
An example I saw on this site was a Singleton pattern like:
static ImageManager &get()
{
static ImageManager imgManager;
return imgManager;
}
I don't really want to use a method like this, but I don't really have any good idea of where the cache should be placed.
I've thought of placing it in a generic Entity class in which the Blocks and Player, etc is derived from, but this seems like it would alienate the manager from things like background images and things that aren't derived from this class. Declaring it in the main loop just seems hectic as it requires me to pass a reference to the manager like Game --> Board --> Block --> etc just to set a sprites image, which seems like poor structure.
My question to you guys then, is how would you suggest I handle creating an instance of my imagecache class. I don't care if you link me sample code, a tutorial, or anything, I'm just lost as to where I should put it so that it's efficient and not cryptic.