Sorry if this is a newbie question, I'm still learning libgdx. I'm using scene2d and I am trying to fade a tooltip into my scene and fade it out after 4.5 seconds.
Everything is working in my code except that tooltip.setVisible()
always overrides the fading animation. I'm wondering if there's a way to set up a callback function or if there's any way to tell when an action has completed so I can trigger setVisible
after the fade animation has completed. I thought about setting up a second timer that triggers after 5 seconds, but that seems like a hacky way to do things.
Here's my TooltipListener class:
public class TooltipListener extends InputListener {
private Actor tooltip;
private InputListener inputListener;
private Timer timer = new Timer();
public TooltipListener(Actor tooltip) {
this.tooltip = tooltip;
}
@Override
public boolean touchDown(
InputEvent event,
float x,
float y,
int pointer,
int button
){
tooltip.setVisible(true);
tooltip.addAction(fadeIn(1f));
tooltip.toFront();
timer.scheduleTask(new Timer.Task() {
@Override
public void run() {
tooltip.addAction(fadeOut(1f));
tooltip.setVisible(false);
}
}, 4.5f);
return true;
}
}