wjc272008 / jmonkeyengine

Automatically exported from code.google.com/p/jmonkeyengine
0 stars 0 forks source link

inputManager.setCursorVisible(false) doesnt work in init #527

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What did you intend to do, what was the expected outcome?

I wanted to start the application with mouse invisible (no cursor).

What outcome do you experience instead?

mouse was visible

Why this bug happens :

flyCam.setEnabled(false) is the cause of the bug,
even if you call inputManager.setCursorVisible(false);
after it, it totally ignores the command.

Why is this bad :
Lets say i have a custom camera, having a cursor prevents rotation when mouse 
exits the screen, this is why it must be disabled for custom cameras.

Code:

package tests.jme;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

/**
 * After disabling flycam, user cannot make the mouse cursor invisible.
 * This is a bug, because it makes custom camera unusable (forced to have a cursor)
 *
 * expected output: cursor should be inviisble.
 */
public class JmeBugCantMakeCursorInvisible extends SimpleApplication
{
   private static final boolean FIX_BUG_WITH_A_HACK = false;

   public void evilCode()
   {
      flyCam.setEnabled(false);
      getInputManager().setCursorVisible(false); //Bug: this command doesnt work in init.
   }

   @Override
   public void simpleInitApp()
   {
      setupCube();
      evilCode();
   }

   @Override public void simpleUpdate(float tpf)
   {
      super.simpleUpdate(tpf);
      if (FIX_BUG_WITH_A_HACK) getInputManager().setCursorVisible(false);
   }

   public void setupCube()
   {
      Geometry geom = new Geometry("Box", new Box(Vector3f.ZERO, 1, 1, 1));
      Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
      mat.setColor("Color", ColorRGBA.Blue);
      geom.setMaterial(mat);
      rootNode.attachChild(geom);
   }

   public static void main(String[] args)
   {
      JmeBugCantMakeCursorInvisible app = new JmeBugCantMakeCursorInvisible();
      app.start(); // start the game
   }
}

Original issue reported on code.google.com by tralalol...@gmail.com on 1 Aug 2012 at 6:31

GoogleCodeExporter commented 9 years ago
Quote to help solve the bug :

@pspeed said:
The fly cam mappings are not initialized until after simpleInit() has finished 
executing. The fly cam is initialized by its own separate app state now. 

Original comment by tralalol...@gmail.com on 8 Aug 2012 at 5:28

GoogleCodeExporter commented 9 years ago
If you don't want flyCam and want to use your own... then remove the app state. 
 That was the entire point of making it an app state in the first place.

Original comment by PSpee...@gmail.com on 8 Aug 2012 at 5:39

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Not a bug.  Reporter is leaving default behavior in that they don't want when 
this default behavior is designed to be easily removed.  It is the 
flyCam.setEnabled(false) that actually causes the issue.

Original comment by PSpee...@gmail.com on 8 Aug 2012 at 5:47