c# - How do I access my "Current Screen" variable from within other classes? -


I have a bunch of screens that come from the base tables called all the GameScreens, which contain various buttons, which can be pressed Go, I want to use the current screen to change. For now, I'm trying to change the screen from the start screen to the overview screen.

I have a variable in my Game 1 class:

  public game screen running screen;  

is set to initialize:

  current screen = starters;  

Then I use the following lines to update and draw the game on which the screen is the current screen:

  CurrentScreen.Update () ; ... current screen. Draw (Streetbatch);  

In my early screen classes, I want to type in some update method like this:

  if (pressed // button) {game .CurrentScreen = OverviewScreen; }  

Now this clearly will not work, but I can not see how to do it. Actually I want to use the current squin variable from within a classroom and want to change it to whatever screen I want, and I feel that there should be a clean way of doing this.

I need some additional information, I think I have not explained it well.

Edit

are startScreen and overviewscreen classes, which mainly include updates and draw methods for the screen. GameScreen is a base class that they get from all The current screen is only for a variable that determines which screen is active.

OK, let me You can add some methods to your Game1 category

  Public Zero SwitchToStartScreen () {...} public void SwitchToOverviewScreen () {...} //  

Then you can add an asset to your start.screen class (and also others)

  public Game 1 guardian {get} Set;}  

and force the manufacturer to pass the Game1 object, in which you specify the parameter parent Then on the special situation you can just use

  Parents. Switch the overview screen ();  

Manually accessing and altering properties from external classes is violating object-oriented principles.

Also, use the abbreviation concise convention because it is difficult to understand what you wrote if any square definitions use Pascal case while others are used in the case of Umal. Your initial screen is more like an object name, while it is used as a class name. The Ether is used to declare classes by default in C # Pascal case that you are not seeing the difference between class and one object.


Comments