tamacalgary.blogg.se

Mouse deselects active window
Mouse deselects active window













I do this by checking to see if the active form’s Text property is equal to the game’s Window.Title property because it’s generic enough for this tutorial, but you can use something else such as checking the object Types. This property “Gets the currently active form for this application.” (MSDN) Using this, we can just add a quick check to see if the game form is active within the application. So, after some searching for different ideas, I managed to figure out a way to do this pretty easily using ’s ActiveForm property. This got really annoying because when I’d switch a tile in the controls form, it would draw the tile in the game form.

mouse deselects active window

I noticed while working on it on my netbook, which doesn’t have a lot of screen real-estate, that when I would click on the controls form while it was over the game window, it would click through. However, in my case, I am making a map editor which uses a windows Form for the controls and the Game window for drawing the tile engine. So, we check to make sure that the mouse X/Y coordinates are above 0 and that they’re below the backbuffer width and height, respectively.įor most games, this should be enough.

mouse deselects active window

Ok, let’s start out in our Update statement with a basic mouse click check: and the fix for the first item above doesn’t work when you have multiple forms in your application.įortunately, there’s an easy way to resolve these! “Great!”, you say, “now how do I do it?”.and it reports the mouse position when it’s outside of the viewable area.XNA captures clicks while the game is not active (i.e.

mouse deselects active window

Unfortunately, the fix for the first problem doesn’t work if you’re using multiple forms in the same application. If you’ve ever worked on an XNA windows game ( note: this only really applies to a windows game) in windowed mode and tried switching applications, you may have noticed that XNA still captures the clicks even when the window is not active! It also reports the mouse position when it’s outside of the window which can cause more issues in and of itself. One of the annoying things with XNA, happens when handling mouse clicks.















Mouse deselects active window