Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  [FPS Camera: Robot.mouseMove() persistency] *closed*  (Read 541 times)
0 Members and 1 Guest are viewing this topic.
Offline GabrielBailey74
« Posted 2013-01-27 05:12:54 »

Hey JGO.

CLOSED:
Wouldn't work with my current setup if implemented with persistency at the moment anyways, thanks for the feedback everyone.

What I'm attempting to do:
I'm attempting to implement a robot to my window that will 'always' keep the mouse centered in the middle of it.
While maybe letting the mouse move 1 pixel each way (maximum), just so we can detect the direction. (not really important as of now)

Problems:
If the mouse is moved rather fast (direction doesn't matter), the robot doesn't 'keep up' and persistently center it. Emo
If the mouse is moved fast enough, it is possible to get the mouse out of the window all together. Stare

Questions:
How can I implement this in a persistent way? (While debugging the mouse is visible, I'd like to see it constantly centered)
Is this just a common ordeal when dealing with a Window not in full screen?
How is this commonly done?

Code at the moment:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
   public void mouseMoved(MouseEvent m) {
      mouseX = m.getX() - 8; // Compensation for JFrame edge width (keeps minimum mouseX == 0)
     mouseY = m.getY() - 30; // Compensation for JFrame title height (keeps minimum mouseY == 0)
     
      final int windowLocationX = getLocationOnScreen().x;
      final int windowLocationY = getLocationOnScreen().y;
      final int centerX = windowLocationX + getWidth() / 2;
      final int centerY = windowLocationY + getHeight() / 2;

      if (mouseX != centerX || mouseY != centerY) {
         if (mouseX != centerX) { /* ... */ }
         if (mouseY != centerY) { /* ... */ }
         robot.mouseMove(centerX, centerY);
      }
   }

Notes:
If someone thinks the reason I'm not getting the persistency I'd prefer is due to the reason of my implementation of compensating for the window's borders, I've executed the program without compensation and it made no difference.
I have tried executing this every frame instead of only executing it when the mouse is moved, still no difference.

Any feedback's welcome guys, thanks.

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #1 - Posted 2013-01-27 05:28:06 »

Quote from: GabrielBailey74 link=topic=28565.msg260180#msg260180
If someone thinks the reason I'm not getting the persistency I'd prefer is due to the reason of my implementation of compensating for the window's borders, I've executed the program without compensation and it made no difference.

I see what you're trying to do, but note that hard-coding the size of the window's title bar and borders is a bad idea.  Different OSes will have different values, let alone if the user has different themes, font sizes, display settings, etc.  You will need to handle such information dynamically.

As for the mouse events, you'll never get one for each pixel the mouse moves.  Your best bet might be to also listen for mouseExited() events and move the mouse back on them as well.  You'll most likely need to handle mouseDragged() events the same way too, since they won't get handled by your mouseMoved() handler.
Offline GabrielBailey74
« Reply #2 - Posted 2013-01-27 05:31:57 »

I see what you're trying to do, but note that hard-coding the size of the window's title bar and borders is a bad idea.  Different OSes will have different values, let alone if the user has different themes, font sizes, display settings, etc.  You will need to handle such information dynamically.

Hey thanks, never knew that.
Regarding mouseDragged, mouseMoved is called inside mouseDragged so centering will still be handled and dragging discarded.

EDIT
: Regarding mouseExited() and moving the mouse back in, that still doesn't constrain the mouse location to the window.

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.

BurntPizza (22 views)
2014-09-19 03:14:18

Dwinin (35 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (88 views)
2014-09-10 06:39:09

Tekkerue (43 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!