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.

Newcomers DBPro Corner / Mouse parimitar?

Author
Message
Inverted
18
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 20th Nov 2006 22:36
Hey guys,
Im wondering,
How would i make it so that the mouse cant go out of certain boundaries.

?

The boundaries i want to mouse to stay in are.
X1=220
Y1=150
X2=1350
Y2=1000

Thanks in advance,
-Inverted

Opposites are different, not wrong
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 20th Nov 2006 23:02
Use the mousex() and mousey() functions to save the mouse positions to variables, change those variables if the mouse is out of bounds, and reposition it with position mouse.



Inverted
18
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 21st Nov 2006 22:34
Thank you

Opposites are different, not wrong
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Nov 2006 02:56
It's only a minor point, but the mouse cannot return floats - only integers.

It will still work with floats, but they are slower than integers which might not matter now - but may do in the future when the program grows and you want to squeeze every last drop of speed out of it.



TDK_Man

Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 25th Nov 2006 15:00 Edited at: 25th Nov 2006 20:57
I forgot to test that code before I posted it; it doesn't compile. Here's the new code:



Inverted, what do you need to limit the mouse boundaries for? If it's for a game, players tend to feel cyber claustrophobic when you change something like that. I've had enough problems with the program freezing and not the mouse not being able to reach task manager, by now I know how to work task manager using only the keyboard.

[edit]

Even integers are not the fastest variables for mouse positions. The mouse position is never negative, and nobody has a screen bigger than 65536 pixels in length or height, so use word variables.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 25th Nov 2006 22:21
Code Dragon, I doubt anybody would notice the speed difference between using integers vs words for the mouse coordinates.
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 25th Nov 2006 22:44 Edited at: 25th Nov 2006 22:45
Speed difference isn't something you'd notice by changing 1 line of code, you have to do hundreds or thousands of optiminizations before you notice the speed difference.

The key is for getting a speed boost fast is to look in the main loop for loops which iterate one hundreds times or more, so any optiminization has one-hundred-fold performance boost. The difference between integers and words usually isn't worth your time thinking about even, but I've made it part of my coding style because my programs tend to nest loops very deeply and iterate many times.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Nov 2006 04:45
Everyone has their own idiosyncrasies when coding, so I don't want to start an argument.

Inverted didn't say (as he should have) what version of DB he was using.

If he was using DB Classic he wouldn't have words as an option whereas integers apply to both versions of DB.

Undoubtedly, there's good reason to use words when you can, but the DB instructions say that the mousex() and mousey() functions return integers so you can't go wrong if you stick with what they say.

Quote: "Speed difference isn't something you'd notice by changing 1 line of code"


Correct. But all those 'one lines of code' will soon add up - especially if he is using DBC.

On that note, you'll note that the code I posted only repositions the mouse if it strays out of the defined area.

TDK

Login to post a reply

Server time is: 2024-11-26 05:42:47
Your offset time is: 2024-11-26 05:42:47