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 / dbPositionMouse() acting strangely...

Author
Message
Wells
15
Years of Service
User Offline
Joined: 25th Mar 2009
Location:
Posted: 26th Mar 2009 00:52
I'm trying to write a function that keeps the mouse restrained to the game window- not that big of a problem. However, I'm getting some funky behavior from dbPositionMouse()- here's what I'm trying to do:



When I call this from my game loop, the mouse shoots straight to the bottom-right corner of the screen! The "debug" outputs show that the "xPos" and "yPos" variables are both increasing extremely quickly. When I replace the xPos and yPos paramaters in dbPositionMouse() with dbMouseX(), and dbMouseY(), the behavior is the same. (Of course, "dbPositionMouse(dbMouseX(), dbMouseY())" is redundant, but it shouldn't be pushing the mouse in to the corner).
Xoddam
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location:
Posted: 26th Mar 2009 03:13
what are the "- xMove;" and "- yMove;" for? it looks like you are trying to subtract the xMove value form the xPos value. :/

like i said im not sure (im a newbie) but that might be a problem.
Wells
15
Years of Service
User Offline
Joined: 25th Mar 2009
Location:
Posted: 26th Mar 2009 19:17
Well that's the thing- I'm trying to do that intentionally (there needs to be a bit more code, but eventually the idea is if the mousemoveX/mousemoveY are too big, put the mouse back where it was).

My problem is that whenever I call dbPositionMouse() with the values of dbMouseX() and dbMouseY(), I get unexpected behavior.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 26th Mar 2009 22:36
So you are trying to keep the mouse in the window? Or do you want it to stay in one spot at all times?

this

will keep the mouse in the middle of the screen at all times.

One more thing: Dark GDK's mouse position functions return numbers that are relative to the game window's coordinates. So, if the mouse isn't within the game window's coordinates, everything gets funky, and that's why your variables start increasing rapidly.

#ifdef _DEBUG
FixBugs(All);
#endif
Wells
15
Years of Service
User Offline
Joined: 25th Mar 2009
Location:
Posted: 27th Mar 2009 01:13
Well, I want to keep the mouse in the window at all times- my idea was to check to see if the mouse was in a certain distance of the edge of the window, and then if it was, reposition it so it'd be "bound" to the window.

However, a problem arises from the fact that the user can move the mouse extremely quickly- if the mouse is centered in the (800x600) window, and the user moves it, say 600 pixels in one cycle (or some other large number), it may escape that bounding zone without ever passing into it.

So, I figured I could get the mousemoveX/Y values each cycle, and if they were greater then a certain value, reposition the mouse to where it was the last cycle. However, it's the implementation that's killing me...
Xoddam
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location:
Posted: 28th Mar 2009 03:35
you need to make variables for x and y that remember the old mouse position from the previous cycle. so that when it bumps the edge it will return to the old x and y position.

or...

you could do something like... if the value of xPos is larger than 800 then it = 800. like so

if(xPos>800){
xPos = 800;
if(xPos<0){
xPos = 0;

i dont know if this would work but if it does you could also do the same for the yPos. play around with it and see. :/

Login to post a reply

Server time is: 2024-09-30 21:37:35
Your offset time is: 2024-09-30 21:37:35