c# - Displaying Different Screens in XNA? -


recently started working xna (coming java) , run problem displaying game screens. when loading xna given game.cs class interpreted set functions drawing single self-contained screen in game. typing code different screens single class messy created below class handle changes:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading;  namespace colonies {     public class gamemanager //manages game screens     {         microsoft.xna.framework.game currentscreen;          public enum screens { menu, game, summary };          public gamemanager()         {             initialize();         }          public void initialize()         {             currentscreen = new menu(this);             ((menu)currentscreen).run();         }          public void changescreen(int i)          {             switch (i)             {                 case 0:                     currentscreen = new menu(this);                     ((menu)currentscreen).run();                     break;                 case 1:                     currentscreen = new world(this);                     ((world)currentscreen).run();                     break;                 case 2:                     currentscreen = new summary(this);                     ((summary)currentscreen).run();                     break;             }         } } 

}

however when 1 of these changes triggered causes error flag telling me can't call game run more once. mean initial estimation having single purpose game screen correct?! should manager instead being queried game screens methods called in main game.cs class?

i.e.

in game.cs update method example:

protected override void update(gametime gametime) {     // allows game exit     if (gamepad.getstate(playerindex.one).buttons.back == buttonstate.pressed)         this.exit();      // todo: add update logic here     agamemanager.getagameobject.doanupdate();     base.update(gametime); } 

so main game class never run again changes displays. correct solution? (so of game class hidden not sure correct way use it)

the game class the entire game. that's why it's called game. if want, can create 'screen' objects, each control different screen, , use game class trying use 'game manager'.

eg:

public static int currentscreen = 0; // screen can change variable when needed   list<screenobject> myscreens = new list<screenobject>(); // populate screens // or menuscreen = new menuscreen(); otherscreen = new otherscreen(); // ...   protected override void update(gametime gametime) {       myscreens[currentscreen].update(gametime);       // or       switch (currentscreen)       {           case 1:                menuscreen.update(gametime); break;           // ...       }       base.update(gametime); } 

and draw(..) same update(..)


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -