Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Check to ensure the game is active before processing events (#196)
Browse files Browse the repository at this point in the history
XNA/MonoGame captures all mouse and keyboard events, even when the window doesn't have focus.  This doesn't make a lot of sense (because it means you can click through other applications to the game window behind them), so this change ensures that the event engine hook checks to see if the game is active before firing any kind of event.
  • Loading branch information
hach-que committed Jun 4, 2017
1 parent 56f76f4 commit d56f33e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Protogame/Core/CoreGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ public bool IsMouseVisible
set { if (_hostGame != null) { _hostGame.IsMouseVisible = value; } }
}

public bool IsActive
{
get
{
return _hostGame?.IsActive ?? false;
}
}

/// <summary>
/// Initializes an instance of a game in Protogame. This constructor is always called
/// as the base constructor to your game implementation.
Expand Down
2 changes: 2 additions & 0 deletions Protogame/Core/ICoreGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface ICoreGame

bool HasLoadedContent { get; }

bool IsActive { get; }

void AssignHost(IHostGame hostGame);

void EnableImmediateStartFromHost();
Expand Down
2 changes: 2 additions & 0 deletions Protogame/Core/IHostGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public interface IHostGame
SpriteBatch SplashScreenSpriteBatch { get; }

Texture2D SplashScreenTexture { get; }

bool IsActive { get; }
}
}
5 changes: 5 additions & 0 deletions Protogame/Events/EventEngineHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public void Render(IGameContext gameContext, IRenderContext renderContext)
/// </param>
public void Update(IGameContext gameContext, IUpdateContext updateContext)
{
if (!gameContext.Game.IsActive)
{
return;
}

UpdateKeyboard(gameContext);
UpdateMouse(gameContext);

Expand Down

0 comments on commit d56f33e

Please sign in to comment.