Reputation: 5384
I have the following problem in LibGDX
. When you move over an Actor
you get the enter event from the ClickListener
and the exit event when you move out of the bounding box of the Actor
. I keep a boolean mouseOver that tells me if the cursor is over an Actor
with these events. But when you click on the Actor
and after releasing the mouse, an exit event is given. So after releasing the mouse click, it is as if the cursor isn't over the Actor anymore, while it is.
How can I keep a correct state for the boolean mouseOver? In other words: how can I know if the mouse is over my Actor when a TouchUp event has occurred as in the above scenario.
Upvotes: 2
Views: 278
Reputation: 1
Set mouseOver to false only if the Actor toActor of exit is not the actor you added the listener to:
myActor.addListener(new ClickListener() {
...
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
...
if (toActor != myActor) // and even myActor's children if it is a Group
mouseOver = false;
}
});
Upvotes: 0
Reputation: 5384
The best hack I found so far is to look at the pointer arg in the exit and enter overrides and look if the mouse is clicked. I'm still looking for a cleaner solution though.
addListener(new ClickListener() {
@Override
public void enter(InputEvent event, float x, float y, int pointer,
Actor fromActor) {
mouseOver = pointer == -1 ? true : mouseOver;
super.enter(event, x, y, pointer, fromActor);
}
@Override
public void exit(InputEvent event, float x, float y, int pointer,
Actor toActor) {
mouseOver = pointer == -1 ? false : mouseOver;
super.exit(event, x, y, pointer, toActor);
}
}
Upvotes: 0
Reputation: 10320
You can override touchUp and set the boolean mouseOver to true there.
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button){
...
mouseOver = true;
}
Upvotes: 1