I'm creating a game in C#, and I've created a ScreenManager
so I can call
ScreenManager.MoveToScreen(typeof(ScreenClassHere))
to move to other game states. However, I feel that my method of creating an instance of the class is... not very optimal. See for yourself.
public static void MoveToScreen(Type s)
{
if (currentscreen != null) currentscreen.Remove();
currentscreen = (Screen)s.GetConstructor(System.Type.EmptyTypes).Invoke(null);
currentscreen.Init();
}
Does anyone know if there's a better way to create an instance of a certain class from a Type
?