mouse buttons (27 posts)

Topic tags: button, mouse
  • Profile picture of phantomliger11 phantomliger11-6p said 7 months, 3 weeks ago:

    Can someone point me to a tutorial for using the mouse button event? or does anyone know how to check if a button is pressed down? Java has a method for the mouseinput called isButtonPressed() but jMonkey doesnt implement it.

  • Profile picture of Sploreg Sploreg200p said 7 months, 3 weeks ago:

    http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_input_system

  • Profile picture of phantomliger11 phantomliger11-6p said 7 months, 3 weeks ago:

    Thank you. In that it has action listener just having an onAction method. When I am trying to implement it it says I should implement the abstract method actionPerformed. What is the difference between these? is actionPerformed just the new version of it or what is it used for? The documentation only says it is invoked when the action occurs which doesnt help much.

  • Profile picture of madjack madjack487p said 7 months, 3 weeks ago:

    The tutorial is self-explanatory. Take the time to read the example in their entirety. Don’t just skim over it.

    You add a mapping

        inputManager.addMapping("WhateverNameSuitsYou",  new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    

    Then you add this to the proper listener (action or analog)

        inputManager.addListener(actionListener, new String[]{"WhateverNameSuitsYou"});
    

    Finally in the actionListener you tell jME3 what to do when that key is triggered.

      private ActionListener actionListener = new ActionListener() {
        public void onAction(String name, boolean keyPressed, float tpf) {
          if (name.equals("WhateverNameSuitsYou") && !keyPressed) {
            isRunning = !isRunning;
          }
        }
      };
    
  • Profile picture of phantomliger11 phantomliger11-6p said 7 months, 3 weeks ago:

    I read it. I wanted to know about the actionPerformed method which is shown here http://download.oracle.com/javase/6/docs/api/java/awt/event/ActionListener.html#actionPerformed%28java.awt.event.ActionEvent%29
    When I try to implement the ActionListener, it tells me I must implement this actionPerformed method because it is an abstract method. I wanted to know what this method is used for. This is not shown in the tutorial you linked to. I completely understood the actionListener and onAction method.

  • Profile picture of Sploreg Sploreg200p said 7 months, 3 weeks ago:

    awt.event.ActionListener is an AWT API class. You want to use com.jme3.input.controls.ActionListener for jme3. You have imported the wrong class. And for listening to the mouse, you want com.jme3.input.controls.AnalogListener

  • Profile picture of phantomliger11 phantomliger11-6p said 7 months, 3 weeks ago:

    Ok thank you. I have been trying to use analog but i need to be able to see if the mouse button is being held down, so I need to use the Action Listener since it has the keypressed boolean. Unless there is a way to do that using the analog listener.

  • Profile picture of Sploreg Sploreg200p said 7 months, 3 weeks ago:

    You use the ActionListener for mouse clicks, AnalogListener for mouse motion events.

  • Profile picture of phantomliger11 phantomliger11-6p said 7 months, 3 weeks ago:

    so if i want to click and hold on an object and move it along with the mouse, I would need to use both?

  • Profile picture of Sploreg Sploreg200p said 7 months, 3 weeks ago:

    Yes. You will want to keep track that the mouse has been pressed using the ActionListener, and then track where it moves with the AnalogListener.

  • Profile picture of phantomliger11 phantomliger11-6p said 7 months, 3 weeks ago:

    Ok. Ill try that. Thank you.

    I was using a ray cast to determine where the box is i am trying to move. Should i still use this with the mouseaxis triggers or should i try to move the box in a ratio to the screen pixel size.

    (sorry for all the questions. i have been stressing over this project for school)

  • Profile picture of glaucomardano glaucomardano252p said 7 months, 3 weeks ago:

    yes, MouseAxisTrigger.

  • Profile picture of Sploreg Sploreg200p said 7 months, 3 weeks ago:

    TestMousePick shows how to pick an object. Just modify it to pick when the button is pressed instead of picking every frame.
    Is this a 3d scene you are working in?
    You can move the box in 3d, say on a plane, by creating a large quad as a surface. Then whenever the mouse is moved, and you have the mouse button down and an object is selected, do a ray cast against the quad. That point it returns in the world is where you will move the object to.

  • Profile picture of phantomliger11 phantomliger11-6p said 7 months, 3 weeks ago:

    Yes it is a 3d scene. Thats how i am trying to do it. What do you mean by a large quad as a surface? I just made a large, flat box to use as a plane.

  • Profile picture of Sploreg Sploreg200p said 7 months, 3 weeks ago:

    Your large flat box as a plane will work as well. Just a surface that you can cast a ray against so you know where your selected item will move to. Like moving an item on the top of a table: you cast a ray against the top of the table from your mouse position to see where it intersects, and that is where the item you are moving moves to.