[quote name='Segun24' timestamp='1329874398' post='4915352']
Hey
I've always just instantiated sprites directly in the main function. Like:
int main(int argc, char **argv) {
Sprite SprPlayerWalk("Graphics/PlayerWalk.png");
Sprite SprPlayerJump("Graphics/PlayerJump.png");
Sprite SprPlayerShowingMiddleFinger("Graphics/PlayerShowingMiddleFinger.png");
while (Open()) {
...
}
return 0;
}
However, I have realised that this is... pretty dumb... Especially if you're going for a project that relies on more than 20 external files.
I've Googled for a while but I can't find ANY information about managing media...
Perhaps I'm searching for the wrong thing, that may have a huge impact on the results.
I have thought about having a class "Graphics" that stores all graphics, and "Audio" for all audio... And just make a loader class that loads everything in to their respective class. However, I'm unsure how tidy that'd really be...
So if anyone has any advice or any guides to refer me to, then I'd highly appreciate it
Thanks in advance.
Initially consider a simple file cache like I
describe here. The example is for caching audio files, but it is equally applicable for graphic files, or more appropriately, template it for any kind of files. Also, I recommend against using naked pointers like I have here, I only do that so in the next chapter I can show how to get rid of them.
That said, I haven't written that next chapter yet....
A caching is pretty simple in the end. What you do is put an object in the middle that handles getting your resource.
So you do something like ResourceLoader::GetGraphic("filename.jpg");
Then in ResourceLoader, it determines if that file has been loaded already, if not, it loads and returns it. If it's already loaded, it simple returns it. Then as time goes on you can start adding whatever complexity you need, like unloading files that haven't been requested recently or the ability to pre-load commonly loaded files, etc...
This is one area XNA did quite well, if in doubt, look at what they did and rip it off.
[/quote]
Thanks. I skimmed a bit over the chapter, and I'll read all chapters over, properly, soon. (It's a bit long, so I'll take my time)
I have an idea on how I can do it though, I'd love some feedback on it.
I am thinking about having a class called "GraphicsManager" in a header file, "GraphicsManager.h" ... and then instantiate it in "GraphicsManager.cpp"
I will then write some functions that can be called like:
GetSprite("mysprite.png");
So whenever I want to use the graphics manager, I can just #include "GraphicsManager.h"
Does this sound like a good design? And why not if it doesn't. Thanks,