public void playMusicBeautifully(String name, Stage stage) { final Music music = musics.get(name); if (music == null) { Logger.error("there is no music for " + name); return; } music.setVolume(0); if (!usesMusic) { disabledMusics.add(music); } else { music.play(); } music.setLooping(true); playingMusics.add(music); Action action = new TemporalAction(5f, Interpolation.linear) { @Override protected void update(float percent) { music.setVolume(percent * volume); } }; stage.addAction(action); replaceAction(music, action); }
public void stopMusicBeautifully(String name, Stage stage) { final Music music = musics.get(name); if (music == null) { Logger.error("there is no music for " + name); return; } final float initialVolume = music.getVolume(); Action action = new TemporalAction(2f, Interpolation.linear) { @Override protected void update(float percent) { music.setVolume(initialVolume - percent * initialVolume); } @Override protected void end() { music.stop(); playingMusics.remove(music); disabledMusics.remove(music); } }; stage.addAction(action); replaceAction(music, action); }
public static void animateCounter(final Label label, final int from, final int to) { label.addAction(new TemporalAction(MathUtils.clamp(Math.abs(to - from) / 30f, 0.5f, 1.5f), new Interpolation.ExpOut(2, 3)) { @Override protected void update(float percent) { label.setText(String.valueOf((int) (from + (to - from) * percent))); } }); }
public static TemporalAction interpolate(TemporalAction action, Interpolation interpolation) { action.setInterpolation(interpolation); return action; }