Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Exit In XNA

Exit In XNA

Scheduled Pinned Locked Moved C#
game-devhelpquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MasterSharp
    wrote on last edited by
    #1

    I have an input class in my XNA game, and I call a method from that class to the main class, to exit the game. (Basically) class Game1 : XNA.blah,blah,blah { Input input; //etc void Initialize() { input = new Input(); } void Update(GameTime gameTime) { input.CheckInput(); } } public class Input : Game1 { public void CheckInput() { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); //or should it be Game1.Exit()? but that doesn't exit } } } *there's more code, but that's not the issue; regualr stuff it starts with So, how would I make the game exit from a different class? Thanks.

    - I love D-flat!

    E 1 Reply Last reply
    0
    • M MasterSharp

      I have an input class in my XNA game, and I call a method from that class to the main class, to exit the game. (Basically) class Game1 : XNA.blah,blah,blah { Input input; //etc void Initialize() { input = new Input(); } void Update(GameTime gameTime) { input.CheckInput(); } } public class Input : Game1 { public void CheckInput() { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); //or should it be Game1.Exit()? but that doesn't exit } } } *there's more code, but that's not the issue; regualr stuff it starts with So, how would I make the game exit from a different class? Thanks.

      - I love D-flat!

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      public class Game1{
      private Input mInput;

      public Game1(){
         mInput = new Input(this);
      }
      

      }
      public class Input{
      private Game1 mGame;

      public void CheckInput(){
          mGame.Exit();
      }
      
      public Input(Game1 game){
          mGame = game;
      }
      

      }

      Need a C# Consultant? I'm available.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups