Hi there,
so following situation. I have a project which is structured something like this.
Game1 -> GameManager -> Module1-X (so multiple instances)
During runtime units are being spawned in each instance of the Module class. Those Units require spritesheets for animation. Let us say each unit has a "Move", "Attack" and "Die" state, each using a individual spritesheet. This makes three Texutre2D instances per unit and with 5 different units this adds up to 15 different Texture files. Those are being passed to the unit's constructor on creation.
As I am loading those textures in Game1's LoadContent method I have to pass them the entire way to the Module class which then uses those textures to instaciate units.
Game1.LoadContent(15x textures) -> GameManager(15x textures) -> Module(15x textures) -> Unit(3x textures)
Imo this has several disadvantages:
- As far as I can judge all those 15 textures are being held in memory of the Module classes the entire time. I would like to avoid that.
- Also passing 15 textures through the project's entire structure makes the classes unreadable and ugly.
- I've got the overall feeling that this is not the way things should be done here.
In order to avoid problem #2 I created a class, its only purpose is to hold all textures that are needed in Module.cs. I called the class AnimationCollection. It holds Texture2D variables and the according getters and setters. So now my Project looks like this.
Game1.LoadContent(new AnimationCollection(15x textures)) -> GameManager(AnimationCollection) -> Module(AnimationCollection) -> Unit(AnimationCollection)
While this does seem to solve problem #2 the other problems remain.
Are there other options on how to handle this problem? I could think of something like loading all content in the Module Class itself, but I never saw this before. I always load my stuff in Game1.LoadContent().
Any ideas, suggestions or expert knowledge is highly appreciated.
Thanks in advance!