What are the pitfalls associated with loading and storing all references to all of your content/assets within a single static class?
I've been trying to ask myself why I would want to instantiate an assets bank and can not think of a good reason to do so.
I have made a static class which enumerates through my game assets and adds each one to a dictionary which I can access (safely exposed, of course) anywhere like so:
var tex = Assets.Image("folder\\easyaspie");
spriteBatch.DrawString(Assets.Font("font2"), new Vector2(100, 100), Color.White);
... you get the picture.
I appreciate that this gets much more complicated when you have so many assets that having them all loaded at once is not a good idea. However, there is nothing to stop you from including selective loading of assets in your static class, as well as having static methods to change the contents of the 'reference banks'.
What do you think?
Edit:
My examples are pretty shallow, I recognise it's not a good idea to attempt to grab the reference of an asset mid-draw and is much better stored locally.
ContentManager
is already a dictionary of loaded content (until youUnload
it). So any implementation of this can simply use it directly, rather than creating and filling a separate dictionary. \$\endgroup\$getInstance()
method that returns that instance. That way you have an API such hat you can access the AssetManager anywhere, but you can still control the lifespan and properly clean up when the application closes. \$\endgroup\$