I have a class in my game called Core where most Managers reside. They go here because all my resources, language data, bitmaps, sounds get loaded by the managers when the game starts up.
After that, the scene manager is created and it initializes the first scene.
The issue comes with sharing data from upper level classes to lower level classes such as scenes.
When a scene starts, it needs to request bitmaps and sounds from the managers. Most scenes also need to look up words to put on buttons based on the language.
The way I do this is by having a sort of Manager manager class. It is constructed with each type of manager that most scenes use. This is passed to the scene manager which passes a pointer to the current scene.
This means each time I have a new manager, I need to change the constructor of the Manager manager and change a few things in the scene manager.
Is there a better way to do this? How is this sort of thing usually done?
Thanks
The most common way of doing this is with a singleton. Just because it’s common though, doesn’t mean it is the best way.
A different way to do the same thing is dependency injection. The constructor for a class will take pointers to the managers that it requires. This gives the advantage of collecting all the dependencies in one place, and lets you substitute test code for any manager easily.