Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Limiting mouse travel

Author
Message
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 16th Jun 2008 22:21
I'm looking for advice on how to handle the mouse leaving the window. One of the games I'm working on is a Breakout type and I'm controlling a paddle (actually a supercollidingjumboxenotronicenerflector) at the bottom of the screen. I seem to be able to handle the mouse's X-coordinate (had to call Scully for advice) going off the right side of the window by testing if the Xposition exceeds the width of the window and set it back to the maximum value. But, if I test for exiting on the left by checking for less than zero and setting it back to zero, it doesn't work. Instead my code bounces it back to the center of the display. I'm actually surprised that it works on the right side.

I can work around it by not allowing it to travel any closer than half the width of the paddle, but I was trying to build some flexibility into how far the paddle could extend outside the window to allow for more control of the angle the ball deflects.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 17th Jun 2008 01:34
I knew how to do this in python. c++ I am not so sure...

Is it 2D or 3D, 3D I can't help, 2D, I think I can.

Your signature has been erased by a mod - 120 high maximum please
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 17th Jun 2008 02:21 Edited at: 17th Jun 2008 02:43
3D coordinates have their origin at 0.0, 0.0, 0.0 and that is usually the center of the window.

Windows uses 0,0 and the origin is the top-left. X/Y are positive and increase going down and right. (By default, that is.)
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Jun 2008 04:49
Quote: "Is it 2D or 3D, 3D I can't help, 2D, I think I can."


It's 2D.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Jun 2008 04:56
Here's the code I'm using.



xTemp is just a way to hold the value since the debugger seems to have some trouble getting the return value of the mousePtr->X() call. leftLimit is set to zero but I know that if it goes off the left side of the window it won't give me a negative number. So I guess I'm looking for a method to tell me that it has gone off the left edge.

Strangely enough, I don't have any code to return it to the center of the window, but that's where it jumps. This is 2D and everything else behaves in 2D coordinates

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 17th Jun 2008 16:11 Edited at: 17th Jun 2008 16:16
The problem with controlling the mouse at window borders is that the velocity of the mouse is uncertain. You have to account for the mouse's speed as it approaches the window frame. I don't know the commands or pointers for your mouse class, but with regular DGDK:

(and the same for the right bound)

Subtracting dbMouseMoveX(), because the value is assumed to be negative if the mouse is moving left. Hope that helps!

NOTE: If the distance from bound to frame is less than the mouse's speed, it will escape.


My site, for various stuff that I make.
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 17th Jun 2008 16:23
why do you have to account for the mouse speed? Why not just put the mouse on the leftlimit when has crossed it?
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 17th Jun 2008 16:29
That would work brilliantly if the program had the same frame rate as the mouse's sample rate. Unfortunately, every modern mouse samples significantly faster than any DGDK program will run. If you just reset the mouse to the limit, it will bounce back, but then move outside the window before the program can loop again.


My site, for various stuff that I make.
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 17th Jun 2008 16:34
hm ok. So either way the mouse will jiggle on the limit? Either outside or inside the limit.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Jun 2008 16:54
Ultimately I think the solution is to make the game run full screen so the mouse can't move outside the window, even on a dual screen system. But some people prefer running in windowed mode. It's definitely better when debugging.

Does anyone know if there's a way to tell if the mouse is no longer within the window's boundaries? I'd hate to have to go to the Window API though.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 17th Jun 2008 17:09
If you go through Windows, you can certainly achieve what you want, but that is a lot of work. A quick fix would be to make the paddle move infinitely left. When it reaches the left bound, reset the mouse and therefore paddle position to the right bound, and vice versa.


My site, for various stuff that I make.

Login to post a reply

Server time is: 2024-09-29 23:20:05
Your offset time is: 2024-09-29 23:20:05