View Full Version : Mouse Outside of Window Problem
Davaris
04-24-2006, 07:12 PM
Hi Everyone,
I'm making a game where I'm using the mouse to move a tank on the screen and the left mouse button to fire. I've had to hide the mouse cursor, so it won't annoy the player, but when you move the mouse to the far side of the screen and fire, sometimes your mouse is outside the window and the window goes to the background.
I was wondering what method you guys use to account for this problem?
Tom Gilleland
04-24-2006, 07:31 PM
We normally write all our games as full screen and not in a window. Then you totally avoid problems like this.
Tom
Not sure if this will work for you, but you can try simply reseting the mouse cursor position every frame (for example, to the center of the screen).
So for each input frame, check the current position of the mouse cursor, calculate the delta from the center of the screen to govern tank movement, then reset the mouse cursor to the center of the screen. Repeat.
All depends on how you are interpreting the mouse input. If it's a "click the ground to go there" type thing, this won't work.
Tertsi
04-24-2006, 11:24 PM
vjvj, you can't just rape the mouse like that when you are in windowed mode. People play games in windowed mode only if their monitor doesn't like other resolutions or more likely they want to switch between applications constantly. So I would just default to full screen mode.
PeterM
04-25-2006, 12:12 AM
I would also recommend going fullscreen only if you use your mouse directly for movement. Or at least giving the pointer back when the user goes to the pause menu/screen.
If however your users need to hold down a button to move, or something like that, you can 'capture' the mouse movement so you still receive mouse move events when the mouse goes outside your window rect.
The appropriate Win32 functions are SetCapture and ReleaseCapture (I think). Call SetCapture on WM_*BUTTONDOWN and ReleaseCapture on WM_*BUTTONUP.
Hope this helps.
Sharpfish
04-25-2006, 01:42 AM
vjvj, you can't just rape the mouse like that when you are in windowed mode. People play games in windowed mode only if their monitor doesn't like other resolutions or more likely they want to switch between applications constantly. So I would just default to full screen mode.
? People play in windowed mode all the time (I do with casual games) not because my monitor doesn't support the resolution (normally standard 640x40 or 800x600 anyway) but because I like to see the crisper gfx of windowed mode in lower res 2D games while still allowing me on game pause (in mouse captured games) or freely (in cursor active games) to wander over to my task bar, browse the net, swap apps (though Alt/Tab is better anyway). If you are playing a game that *needs* the mouse to control something on screen then the small price the user pays is that while doing that the mouse is not available to move around the desktop without "simply" pressing pause in the game first (more likely pressing "escape" or something as there is prob no cursor on screen). It would be wrong to send the Original poster around the houses thinking he can't do what 90% of other games of that type do (including windowed games)
As for the mouse, there is nothing wrong with holding onto it in the centre of the screen (hidden) and showing it (reactivating it normally) on game pause/menu display/exit. I have seen hundreds of games that do not use a mouse cursor in game do this.
Also it is a cop out to only provide fullscreen in games if your game can realistically be used in windowed mode also. Windowed mode is not hard to accomodate with a little forethought and even for non casual games is sometimes welcome (even Doom3, HL2 and UT2k4 have WINDOWED modes and restrict the mouse to some hidden centre, reactivating on menu display). I wouldn't imagine they are often played in windowed mode (for your typical immersion reasons ;) ) but the option is there and it works fine.
Nikster
04-25-2006, 02:07 AM
as PeterM says with release/capture mouse if using win32, however, I dispise anything that locks a mouse to a window when running in a windowed mode, what's the point ? but that's just me, maybe :)
Sharpfish
04-25-2006, 02:17 AM
I dispise anything that locks a mouse to a window when running in a windowed mode, what's the point ? but that's just me, maybe :)
The point is that you cannot avoid it. It is part of "playing the game". Don't think about it from a typical app point of view. The fact is that there are many games that restrict/hide/centre the cursor in windowed mode games purely because it is the only sane way to handle games that use the mouse to directly control things (look at any breakout style game of which there are hundreds - they all do the same, they all work great). The mouse will pop up as a regular "move anywhere on the desktop" cursor as soon as you pause the game. If you think people are going to be playing a game like breakout (or more action type games that are not cursor on screen like match3's) and will want to surf the net or move to mirc *without* pausing their game first then it just doesn't happen. That only happens with real casual games which usually tend to have a mouse cursor on screen anyway (and therefore do not need restricting). :)
Don't get me wrong, I'm not advocating "raping" someones system in non-standard ways, but that is more a discussion of ways around the problem while still allowing windowed mode. I am only talking about the original posters question "what do people do to get around it" and restricting the hidden cursor is what they do. I wonder sometimes how much research people do into the games they talk about, all the evidence is there without me having to say it! ;)
edit > should clarify, I'm with you guys on detesting a game in windowed mode that captures the mouse and *never* lets you get control of it (via pausing). They are damn annoying and perhaps that is the type of game you are referring to moreso. It feels like they have control of your system and you have to quit to get anywhere! The pause thing works really well as the only time the mouse is captured is while you are actively playing the core-game (not even on menus etc in which are free to move around the desktop as normal).
Nikster
04-25-2006, 03:00 AM
The reason I have issues with it, is because if I see a window I expect it to behave like a window, things like how do you move a window etc, as for games like breakout, I'd sooner use keyboard over mouse anyway, but again, that's just me ;) and as for the original posters question, I don't see how you'd move a tank with a mouse, even the tanks in battlefield1942 I used keys, apart from the gun, maybe that's what the original poster is doing, I don't know.
But yes, a solution is to lock it.
? People play in windowed mode all the time (I do with casual games) not because my monitor doesn't support the resolution (normally standard 640x40 or 800x600 anyway) but because I like to see the crisper gfx of windowed mode in lower res 2D games while still allowing me on game pause (in mouse captured games) or freely (in cursor active games) to wander over to my task bar, browse the net, swap apps (though Alt/Tab is better anyway). If you are playing a game that *needs* the mouse to control something on screen then the small price the user pays is that while doing that the mouse is not available to move around the desktop without "simply" pressing pause in the game first (more likely pressing "escape" or something as there is prob no cursor on screen). It would be wrong to send the Original poster around the houses thinking he can't do what 90% of other games of that type do (including windowed games)
As for the mouse, there is nothing wrong with holding onto it in the centre of the screen (hidden) and showing it (reactivating it normally) on game pause/menu display/exit. I have seen hundreds of games that do not use a mouse cursor in game do this.
Also it is a cop out to only provide fullscreen in games if your game can realistically be used in windowed mode also. Windowed mode is not hard to accomodate with a little forethought and even for non casual games is sometimes welcome (even Doom3, HL2 and UT2k4 have WINDOWED modes and restrict the mouse to some hidden centre, reactivating on menu display). I wouldn't imagine they are often played in windowed mode (for your typical immersion reasons ;) ) but the option is there and it works fine.
Agreed entirely :)
The method I suggested above was what I did for Meridian 59. It runs in a window and the cursor is always hidden when the mouse is locked. Any action that requires a cursor (chatting, looking at inventory, alt-tabbing to another program) unlocks and unhides the cursor. It works fine.
IIRC I first tried PeterM's method but couldn't get it to work. I was probably just using it wrong, though :D
Hiro_Antagonist
04-25-2006, 12:38 PM
vjvj, you can't just rape the mouse like that when you are in windowed mode. People play games in windowed mode only if their monitor doesn't like other resolutions or more likely they want to switch between applications constantly. So I would just default to full screen mode.
As Sharpfish pointed ouit, there are all sorts of games that play in a window like this.
Although, if you do this, I recommend only doing it in the gameplay modes that require the mouse to be hidden/inactive. If a player hits escape to go to a menu, for instance, restore mouse control and let it escape your window. This is how first-person shooters work in a window.
That way, players can still pretty easily change windows, and of course, they always have alt-tab. (I'm pretty sure most players who insist on playing in a window know how to alt-tab...)
-Hiro_Antagonist
Pogacha
04-26-2006, 05:01 PM
You can use Dinput exclusive mode, you get total control without screen limits and other common problems ... Then when the user hits Esc the program returns the mouse cooperative level and the cursor appears again.
Edit: Is alt-tab safe too ;)
Thorbrian
04-26-2006, 05:31 PM
We normally write all our games as full screen and not in a window. Then you totally avoid problems like this.
Full-screen doesn't necessarily avoid these problems (although certain flavors of DirectInput in DirectX fullscreen do).
Dual monitor setups often have problems with the mouse cursor going over to the other screen while playing, then clicking to switch to the desktop. It's very annoying, and even many older AAA PC titles have this problem (like GTA3)
PeterM
04-27-2006, 12:05 AM
Hopefully I'm not diverting the topic too much, but do Macs suffer from this kind of problem too?
Tom Gilleland
04-27-2006, 11:23 AM
Macs have similar challanges. Dual monitors users for example, but this is a pretty small percentage of the users. In fact I would argue that the Mac user is more accustomed to running things in separate floating Windows, as opposed to Windows users leaning toward full screen programs. We normally write most our games in Full Screen mode primarily for artistic reasons. Of course I feel very strongly about the presentation of the game, and full window gives you the most control. My goal is to get the player to say "Wow" the first time they launch the game. You know, the whole first impression thing. Probably the best solution is to have an optional windowed mode for those users who jump in and out of the game. I would expect this is a fairly small percentage in the causual game demigraphic. I always try to design usability for my Mom or Grandmother.
I think it is bad design to have a mouse tied to a specific window. What's the point of having a window if you can't click outside of it - might as well go full screen. And you're not following standard Windows/Mac design guidelines. I try to avoid all the tech support that I can. So if you have to have it in a window, and the players mouse is going to be all over the screen, then the pause/unlock mouse solution is the only viable one in this case. I think this is most appropriate for small windowed games like the cool Titans Attack, or the all those Tetris games.
Tom
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.