c# - XNA - How to Exit Game from class other than main? -
how make game can exit not have code in main class, have in different class?
you can create method:
//inside of game1.cs public void quit() { this.exit() }
i'm assuming want quit game on menu component, in case need pass instance of game1 component, perhaps add parameter in menu components update method.
public void update(gametime gametime, game1 game) { if(key pressed) { game.quit(); } }
i'm not sure if there other ways... perhaps finding way "force" close button press.
in order send instance of game1.cs:
//in game1.cs //in update method public void update(gametime gametime) { //sends current game instance other classes update method, // quit might called. otherclass.update(gametime, this); //where 'this' actual keyword 'this'. should left 'this' }
Comments
Post a Comment