Mojo event for Window OnDeactivated

Monkey Forums/Monkey Programming/Mojo event for Window OnDeactivated

Erik(Posted 2013) [#1]
Here are some code to don't update your game if the window loses focus,
this only works for XNA and you have to modify the \targets\xna\modules\native\monkeytarget.cs file.

It would be very good if OnDeactivated was added as an mojo event like OnClose and supported for the
desktop targets I think.

Without it mouseclicks etc just go right through other windows to the game if you are alt-tabbed.

  public bool windowactive = true;
  protected override void OnDeactivated(Object sender, EventArgs args){
    windowactive = false;
  }
  protected override void OnActivated(Object sender, EventArgs args){
    windowactive = true;
  }
  protected override void Update( GameTime gameTime ){
    if (windowactive)
    {
      _game.Update( gameTime );
      base.Update( gameTime );
    }
  }