@Neurological wrote:
I'm coming from Unity, wanted to drop it for something that let me some more freedom on how game work instead of having to rewrite whole systems and hack around the existing ones, so I thought was better to start from scratch then.
I'm getting around how MonoGame is structured and is pleasant to use. At the moment I have a doubt that I would like an input from someone experienced with the framework. Noticed that classes like GraphicsDeviceManager and GraphicsDevice are dependant from the base Game class, so referencing the two from outside it can be a bit problematic at times.
First try was to pass the Game class in the constructors of the classes that should use it, but it quickly become spaghetti code as not all components need that kind of info, so I thought to make a static class having both those other two in it for a global reference, but I'm unsure if is a good idea, this is what I do:
In the Game based class on Initialize I populate a static class called Display, with those simple lines:
Display.SetDevice(GraphicsDevice); Display.SetScreen(graphics);
Then this is my static Display class:
public static class Display { static public GraphicsDevice Device { get; private set; } static public GraphicsDeviceManager Screen { get; private set; } static public void SetDevice (GraphicsDevice device) { if (Device == null) Device = device; } static public void SetScreen (GraphicsDeviceManager screen) { if (Screen == null) Screen = screen; } }
So can just cal lDisplay.Screen or Device from other classes and have it working, but would this be a good method in the long run, or what could be the alternatives?
Thanks.
Posts: 2
Participants: 2