3

I want to use the exit() method in the InputListener to see wheter the cursor is inside the button or not.

Here is the explanation in the libGDX docs.

public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)

Called any time the mouse cursor or a finger touch is moved out of an actor.

But when I put my cursor on the button and then move it outside the button, the method is not called. I am testing it by a System.out.println("exited"); and I get nothing in the console.

EDIT:

LibGDX Version: Latest Stable Nightlies

InputListener implementation:

//This button class is a custom class to make button creation easier. This is the constructor.
public Button(Vector2 position, String packLocation, String text, Stage stage, BitmapFont font, Color color) {

//Removed buttonStyle creation etc. to shorten the code.
    button = new TextButton(text, buttonStyle);
    button.setPosition(position.x, position.y);
    stage.addActor(button);
    Gdx.input.setInputProcessor(stage);
    pressed = false;

    button.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            pressed = true;
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            pressed = false;
        }

        @Override
        public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
            System.out.println("exited");
        }
    });
}

EDIT:

Hovering over the button also does not change the texture of the button as I set it to like so:

buttonStyle.over = skin.getDrawable("over");

But clicking does.

Sierox
  • 459
  • 3
  • 18
  • The exit method works fine for me. Which libgdx version do you use? Where and how do you add the listener to your button? Please add the relevant code. – donfuxx Jul 16 '14 at 19:49
  • @donfuxx Did the editing. **Note:** touchUp and touchDown ARE working. Exit is not. – Sierox Jul 16 '14 at 20:09
  • copy-pasted your listener to some of my buttons and it worked fine like this. Are you testing this in Desktop project of libgdx? Note that there is no Mouse cursor in Android. – donfuxx Jul 16 '14 at 20:41
  • @donfuxx I don't get the message "exited" in my Android device nor in my Desktop. Maybe the button initilization is wrong? – Sierox Jul 17 '14 at 08:51
  • @donfuxx ALSO, the button's texture doesn't change when my mouse HOVERS over it even though I did set a texture for it so I think there is a general problem with enter() and exit()... – Sierox Jul 17 '14 at 10:50

1 Answers1

6

After searching for a couple hours I finally found what was missing. stage.act(); had to be called in the render method. This both gave functionality to the texture change when we hover over the button and also the enter/exit methods in the InputListener.

Sierox
  • 459
  • 3
  • 18