Listeners inside of a control

When I have the window selected the program should trap my mouse inside of the screen and make it disappear allowing for head movement with the mouse. The problem is that the mouse is never enters this state it simply floats over the application window allowing me to move it outside of the application. The application does respond to the mouse input whenever the mouse is over the window allowing the player to move their head about 10 degrees in any direction so it is responding to the input correctly. The mouse just does not disappear when the game is selected or affect the game when it is not over the window and the window is selected.



Thanks.

By default the cursor is invisible (and thus is captured) by the application.



You can change that by using

[java]

inputManager.setCursorVisible(true);

[/java]



Based on what I understand of your post you probably set it visible somewhere. Leave it invisible and turn it visible only when needed, like when the inventory is triggered or some other action that needs the mouse. Once that state is no longer true (inventory window closed) then set the cursor back to invisible.



Technically that should work fine. I do it that way and I have no problem (except I do it in reverse; by default it’s visible. It goes invisible only when the right mouse button is clicked).

I only found one instance where I set the cursor visible and it was in a method that is not called. I tried removing all the lines of my code that affect the cursor visibility with no effect.



EDIT: I added inputManager.setCursorVisible(false); inside of simple update and it fixed the problem but I don’t understand why It only works when I do that. I originally tried to place it inside of the simple initiate app method but that only had a temporary effect (It only lasted until the app was completely loaded).



Any ideas on what could cause the cursor to become visible after simple initiate app runs?



Thanks.

@darklightning7 said:
I only found one instance where I set the cursor visible and it was in a method that is not called. I tried removing all the lines of my code that affect the cursor visibility with no effect.

EDIT: I added inputManager.setCursorVisible(false); inside of simple update and it fixed the problem but I don't understand why It only works when I do that. I originally tried to place it inside of the simple initiate app method but that only had a temporary effect (It only lasted until the app was completely loaded).



Do you ever do flyCam.setEnabled(false)?

The only point of flyCam is for controlling the camera movement... so if you aren't using it for controlling the camera then you should remove it and just rely on your own controls.

I have done that its actualy the first statement in my simpleInitApp() method. :slight_smile:



I will take a good look at all of my camera related statements to see if there is something else that is causing this.



Any other ideas?



Thanks.

If flyCam is disable then it will turn on the cursor… but I don’t think it’s smart about how it does it so may do it after simpleInit() is done.



At any rate, if you don’t want flyCam then remove the FlyCamAppState and you won’t have to deal with it at all.

How would I go about removing the flyCamAppState?

Is there an article or documentation on jme appstates?



Thanks.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:intermediate:simpleapplication?s[]=flycamappstate



Scroll to the bottom.

That is exactly what I was looking for. I tried to remove it directly did not realize you have to use get state first.



That fixed my problem thanks.

I did a little playing around with flyCam.setEnabled() and removing the FlyCamAppState. I found that setting the fly camera disabled causes the problems with the mouse. Then to correct the problems you have to remove the FlyCamAppState. It seems odd that leaving fly cam enabled does not appear to affect the game at all.



Thanks for all the help everyone.

Fly cam enabled, mouse cursor is not visible, mouse moves the view, keys move the view (unless you take a sledge hammer to input manager and clear them all… yuck)



Fly cam disabled, mouse cursor is visible. Mouse moves no longer move the view, etc…



Removing the app state means that there is no fly cam.



Because fly cam is now controlled by an app state (so that it can be removed), it doesn’t actually get initialized until after simpleInit()… and I guess when it sees that it is disabled it turns the mouse back on. Probably some checks that could be added to catch this edge case but really it’s doing the right thing from a certain perspective.