Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  how to restrict mouse moving area?  (Read 2800 times)
0 Members and 1 Guest are viewing this topic.
Offline misterX

Junior Member




java forever!


« Posted 2003-03-23 10:08:44 »

hi,
i know this post doesn't really match in Java2D but i didn't know where to put it else!

my question is:
is it possible to restrict the mouse moving area? if yes, how?
for example that the mouse pointer can't go outside the window, or even better, that the mouse pointer can't go outside a specific box inside the frame.
And how to swap between "restricted mode" and "free mode"?
Offline mill

Junior Member




popcorn freak


« Reply #1 - Posted 2003-03-23 11:07:46 »

have a look at java.awt.Robot

Offline misterX

Junior Member




java forever!


« Reply #2 - Posted 2003-03-23 11:54:11 »

nice idea, but doesn't fit very well.
When i put conditions near the window borders to keep it inside, the cursor can still go out of the window if it is moved fast enough.
any other solution?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline mill

Junior Member




popcorn freak


« Reply #3 - Posted 2003-03-23 13:54:44 »

it should do the trick.. how are you using it? you are using it together with a MouseMotionListener right?

Offline misterX

Junior Member




java forever!


« Reply #4 - Posted 2003-03-23 14:21:13 »

yes, exactly.

i put "conditions" in the MouseMotionListener like:
if (e.getX() < 10)
  myRobot.mouseMove(10, e.getY());

Should i use it another way?
Offline mill

Junior Member




popcorn freak


« Reply #5 - Posted 2003-03-23 14:44:07 »

hmm it depends on the resolution of the mouse i guess. this is the same problem found in games. if the movement is jerky then a car for instance can drive through a wall.

the trick is to see where the cursor is going to be next, that is getX()+dx. save the old getX in a variable and calc dx and then use that in the if-condition.

i haven't used Robot in a long time and it worked pretty well, but this should do the trick. anyone else has any ideas?

Offline mill

Junior Member




popcorn freak


« Reply #6 - Posted 2003-03-23 14:48:47 »

forgot to mention that when you set it to a new position, remember to substract the speed which you moved the mouse, as in maxX-dx;

Offline misterX

Junior Member




java forever!


« Reply #7 - Posted 2003-03-23 16:27:47 »

Quote

the trick is to see where the cursor is going to be next...

thanks for the idea, but it is impossible to know. i don't get the x and y variations but only the absolute pos.
And when you go fast enough, you can go from the pos (50, y) to 'out of frame' in one move.
So the solution isn't working fine.

It could maybe work if i knew how to get the absolute mouse coord (outside the window), but i don't know if it's possible either.
Lastly, since it's not really the purpose of 'Robot', it wouldn't be a very nice solution...

Maybe there is another simplier solution... i hope.
thanks anyway.
Offline misterX

Junior Member




java forever!


« Reply #8 - Posted 2003-03-23 16:30:17 »

has anyone another solution?
Offline mill

Junior Member




popcorn freak


« Reply #9 - Posted 2003-03-23 16:38:20 »

Quote

thanks for the idea, but it is impossible to know. i don't get the x and y variations but only the absolute pos.


well, if you save your last pos in lastX, then dx would be getX()-lastX, as simple as that. it should work.

anyway, i'll think about some other solution for a while.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline misterX

Junior Member




java forever!


« Reply #10 - Posted 2003-03-25 14:24:47 »

Quote

It could maybe work if i knew how to get the absolute mouse coord (also outside the window), but i don't know if it's possible either.

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #11 - Posted 2003-03-27 13:53:16 »

Why do you care that the mouse goes outside a certain area if you can still "put it back" with the Robot as when you find out?
If it is just the visual distraction of the pointer going outside your bounds, then maybe you can work around it by using a custom cursor to hide the pointer completely, then draw your own cursor that you restrict to the boundary area in your own drawing code.
Anyway give a bit more info about what end effect you are after and maybe we can come up with more ideas.

Offline mill

Junior Member




popcorn freak


« Reply #12 - Posted 2003-03-27 13:58:10 »

yup, i'm puzzled as well. what i suggested is what i believe the normal way to do it and it works for me.

a common thing is that people don't "close" a thread, as in saying "i managed to get things working, thanks for your help". it's much easier to not to post anything.

Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #13 - Posted 2003-03-27 16:52:49 »

totally unrelated to java, but...

Quake3 when played in a window has the annoying habit of occasionally losing the focus. Angry

Ive put it down to the mouse momentarily getting outside the frames borders at the exact same time as a mouse click occuring.  Shocked

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #14 - Posted 2003-03-27 18:30:46 »

Heh, that's pretty funny.  I've become a bit peeved when accidentally clicking a different window in XBoing and having to rapidly switch between windows before the ball comes down again, but I expect the same happening in Quake3 would turn the air blue... Grin

Hellomynameis Charlie Dobbie.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (15 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (10 views)
2014-07-29 10:59:34

E.R. Fleming (28 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!