Lets say I have my C# program running, there is a button on the screen that if I put my mouse over it, it will change the game to a new page. Now I put another window in front of the project, lets say Google Chrome, and I am searching the web and clicking things, as I do that the project that is running right now is interacting with the mouse still and can have the button pressed even if I can't see the button. How do I turn this interaction off?
Asked
Active
Viewed 90 times
0
-
Your title and question are hard to read and unclear. You should rephrase them to be more understandable if you expect to get an answer. – Patrick Quirk Dec 19 '13 at 15:20
-
@PatrickQuirk I have updated the question to hopefully help people understand the question, it was a tricky topic to name, sorry about the miss-communication. – Ryan Foy Dec 19 '13 at 15:27
-
http://stackoverflow.com/questions/9550640/making-sure-my-xna-game-has-focus-before-handling-mouse-and-keyboard-events Possible duplicate? – SQLSavant Dec 19 '13 at 15:36
-
@cloyd800 I think that this is. I would like to know how exactly Game.IsActive is incorporated into the program. I tried using it in the main class, in the update method and is having an error. IsActive is not showing up. – Ryan Foy Dec 19 '13 at 15:43
1 Answers
0
By using IsActive in your implementation of the Game class (called Game1 by default), you can avoid receiving input while your game is not in focus.
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
if (!IsActive)
{
return;
}
// ... do regualr update.
}
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.isactive.aspx
Alternatively, if you already have some Game State Management system, you can override the OnDeactived method in Game. This function will get called when the game looses focus.
protected override void OnDeactivated(object sender, EventArgs args)
{
base.OnDeactivated(sender, args);
// If we are in a state which it makes sense to pause the game, then do it now.
if (GameObjectManager.pInstance.pCurUpdatePass == BehaviourDefinition.Passes.GAME_PLAY)
{
GameObjectManager.pInstance.pCurUpdatePass = BehaviourDefinition.Passes.GAME_PLAY_PAUSED;
}
}
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.ondeactivated.aspx

Goose
- 1,307
- 2
- 14
- 28