Hello!
So I’m trying to apply a “cooldown” effect to my buttons such that after a skill is fired, the button should turn black and a timer appears over it. I can get the button to turn black but I can’t seem to remove the black effect and thus see the original icon again after the timer runs out.
Because it is possible to remotely fire skills via keyboard shortcuts, I don’t feel like having the button subscribe to a Release EffectEvent is what I need.
Right now my code looks something like this…
private class buttonCooldown extends AbstractControl {
private float countdown;
private MyButton button;
private Effect buttondim;
public buttonCooldown(int length, MyButton button) { //no important difference from a normal button
this.countdown = length;
this.button = button;
button.setFontColor(ColorRGBA.White);
button.setFontSize(36);
buttondim = new Effect(Effect.EffectType.ColorSwap, Effect.EffectEvent.Show, countdown);
buttondim.setColor(ColorRGBA.Black);
buttondim.setElement(button);
screen.getEffectManager().applyEffect(buttondim);
}
@Override
protected void controlUpdate(float tpf) {
if (countdown > 0) {
countdown -= tpf;
button.setText(new Integer((int) countdown + 1).toString());
} else {
button.setText("");
//screen.getEffectManager().removeEffect(buttondim) something like that?
spatial.removeControl(this);
}
A separate issue but may be important: using
this.button.addEffect(buttondim);
actually doesn't turn the button black at all, although some other effects work.
Thanks in advance!