I’m extremely new to monogame but have made a few games from tutorials and got to grips with everything apart from content management. Everyone does it a different way and for a beginner who doesn’t really care about the debate, it is incredibly difficult to learn what to do. The consensus for small games seems to be simply loading all assets at the beginning of the game, which sounds simple enough. However, what is the best way to access these loaded textures? Some say having a singleton or static class to contain the content, but there is always some sharp rebuttal to this idea. Passing them as parameters seems to be the most sensible to me, but also seems ugly. If in my player class i have many assets, it seems silly to flood the class with all of the assets.
TLDR: Everyone has a different opinion on accessing assets but I would appreciate someone just recommending and giving an example of the best method for a beginner.
This method certainly seems to be the easiest but is it good practice? Suggestions such as this on other threads are quite harshly criticised. What is the downsides to this method?
I like to store everything in a static assetmanager class.
And I call assetmanager.initialise() when loading the game which loads all the assets.
I store them in dictionaries with an enum as a key. It might seem strange but I prefer it over using strings because you can never call an asset up with a name that doesn’t exist.
Eg dictionary<texture2dType, textured2d)
And have a method Texture2d GetTexture2d(Texture2dType type) which returns the texture from the dictionary.
Ignore the haters. There’s no need to use something more complex unless your engine starts growing and you need something more. Anyway, this code is easy enough to refactor down the line.
Good practice is a myth anyway. There are many valid ways to code the same thing. Best not to paralyze yourself mentally until you have a reason to.