So, i\'m working on a jumping animation and it works fine but i\'m trying to get it so an image will be shown for a certain amount of time (time= time spent in the air) if a but
In general you can do this with a PauseTransition
:
Duration delay = ... ;
PauseTransition timer = new PauseTransition(delay);
timer.setOnFinished(evt -> undoWhatIDidToUI());
doSomethingToUI();
timer.play();
So, if I understand you,
Duration delay = ... ; // time for a jump
PauseTransition jumpTimer = new PauseTransition(delay);
jumpTimer.setOnFinished(evt -> iview.setImage(imgninja));
iview.setImage(jumpingImage);
jumpTimer.play();
It might be easier though to just detect if you are currently jumping in the animation timer, and call setImage(...)
with the appropriate image depending on whether you are jumping or not. (Calling setImage(...)
with the same image as is currently used is basically a no-op, so there should be no performance issues doing that.) This would, I think, just look like:
@Override
public void handle(long now) {
// existing code...
if (jumpforce < 0) {
iview.setImage(jumpingImage);
} else {
iview.setImage(imgninja);
}
// ...
}