From ba240797d899cc1caabe54601bccea86b30ad07a Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Thu, 19 Nov 2015 17:47:46 -0500 Subject: [PATCH] Replaced all linear fade-out transitions with eased transitions. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/Opsu.java | 5 +- src/itdelatrisu/opsu/states/ButtonMenu.java | 16 ++-- .../opsu/states/DownloadsMenu.java | 6 +- src/itdelatrisu/opsu/states/Game.java | 12 +-- .../opsu/states/GamePauseMenu.java | 6 +- src/itdelatrisu/opsu/states/GameRanking.java | 7 +- src/itdelatrisu/opsu/states/MainMenu.java | 8 +- src/itdelatrisu/opsu/states/OptionsMenu.java | 6 +- src/itdelatrisu/opsu/states/SongMenu.java | 14 ++-- .../transition/DelayedFadeOutTransition.java | 1 + .../transition/EasedFadeOutTransition.java | 83 +++++++++++++++++++ 11 files changed, 123 insertions(+), 41 deletions(-) create mode 100644 src/org/newdawn/slick/state/transition/EasedFadeOutTransition.java diff --git a/src/itdelatrisu/opsu/Opsu.java b/src/itdelatrisu/opsu/Opsu.java index 7cabc6dd..82e9f553 100644 --- a/src/itdelatrisu/opsu/Opsu.java +++ b/src/itdelatrisu/opsu/Opsu.java @@ -43,13 +43,12 @@ import java.net.InetAddress; import java.net.ServerSocket; import java.net.UnknownHostException; -import org.newdawn.slick.Color; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Input; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.transition.FadeInTransition; -import org.newdawn.slick.state.transition.FadeOutTransition; +import org.newdawn.slick.state.transition.EasedFadeOutTransition; import org.newdawn.slick.util.DefaultLogSystem; import org.newdawn.slick.util.FileSystemLocation; import org.newdawn.slick.util.Log; @@ -238,7 +237,7 @@ public class Opsu extends StateBasedGame { if (UI.getCursor().isBeatmapSkinned()) UI.getCursor().reset(); songMenu.resetGameDataOnLoad(); - this.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + this.enterState(Opsu.STATE_SONGMENU, new EasedFadeOutTransition(), new FadeInTransition()); return false; } diff --git a/src/itdelatrisu/opsu/states/ButtonMenu.java b/src/itdelatrisu/opsu/states/ButtonMenu.java index 08abdaea..da13dfbc 100644 --- a/src/itdelatrisu/opsu/states/ButtonMenu.java +++ b/src/itdelatrisu/opsu/states/ButtonMenu.java @@ -46,8 +46,8 @@ import org.newdawn.slick.Input; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; -import org.newdawn.slick.state.transition.EmptyTransition; import org.newdawn.slick.state.transition.FadeInTransition; +import org.newdawn.slick.state.transition.EmptyTransition; /** * Generic button menu state. @@ -456,7 +456,7 @@ public class ButtonMenu extends BasicGameState { @Override public void click(GameContainer container, StateBasedGame game) { SoundController.playSound(SoundEffect.MENUBACK); - game.enterState(Opsu.STATE_MAINMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_MAINMENU, new EmptyTransition(), new FadeInTransition()); } }, CLEAR_SCORES ("Clear local scores", Color.magenta) { @@ -465,7 +465,7 @@ public class ButtonMenu extends BasicGameState { SoundController.playSound(SoundEffect.MENUHIT); BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); ((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.BEATMAP, node); - game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); } }, DELETE ("Delete...", Color.red) { @@ -483,7 +483,7 @@ public class ButtonMenu extends BasicGameState { @Override public void click(GameContainer container, StateBasedGame game) { SoundController.playSound(SoundEffect.MENUBACK); - game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); } }, DELETE_CONFIRM ("Yes, delete this beatmap!", Color.red) { @@ -492,7 +492,7 @@ public class ButtonMenu extends BasicGameState { SoundController.playSound(SoundEffect.MENUHIT); BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); ((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.BEATMAP_DELETE_CONFIRM, node); - game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); } }, DELETE_GROUP ("Yes, delete all difficulties!", Color.red) { @@ -507,7 +507,7 @@ public class ButtonMenu extends BasicGameState { SoundController.playSound(SoundEffect.MENUHIT); BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); ((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.BEATMAP_DELETE_SELECT, node); - game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); } }, CANCEL_DELETE ("Nooooo! I didn't mean to!", Color.gray) { @@ -521,7 +521,7 @@ public class ButtonMenu extends BasicGameState { public void click(GameContainer container, StateBasedGame game) { SoundController.playSound(SoundEffect.MENUHIT); ((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.RELOAD); - game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); } }, RELOAD_CANCEL ("Cancel", Color.red) { @@ -536,7 +536,7 @@ public class ButtonMenu extends BasicGameState { SoundController.playSound(SoundEffect.MENUHIT); ScoreData scoreData = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getScoreData(); ((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.SCORE, scoreData); - game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); } }, CLOSE ("Close", Color.gray) { diff --git a/src/itdelatrisu/opsu/states/DownloadsMenu.java b/src/itdelatrisu/opsu/states/DownloadsMenu.java index 09c98790..a9c5b7cf 100644 --- a/src/itdelatrisu/opsu/states/DownloadsMenu.java +++ b/src/itdelatrisu/opsu/states/DownloadsMenu.java @@ -62,8 +62,8 @@ import org.newdawn.slick.SlickException; import org.newdawn.slick.gui.TextField; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; +import org.newdawn.slick.state.transition.EasedFadeOutTransition; import org.newdawn.slick.state.transition.FadeInTransition; -import org.newdawn.slick.state.transition.FadeOutTransition; import org.newdawn.slick.util.Log; /** @@ -625,7 +625,7 @@ public class DownloadsMenu extends BasicGameState { if (UI.getBackButton().contains(x, y)) { SoundController.playSound(SoundEffect.MENUBACK); ((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset(); - game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_MAINMENU, new EasedFadeOutTransition(), new FadeInTransition()); return; } @@ -893,7 +893,7 @@ public class DownloadsMenu extends BasicGameState { // return to main menu SoundController.playSound(SoundEffect.MENUBACK); ((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset(); - game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_MAINMENU, new EasedFadeOutTransition(), new FadeInTransition()); } break; case Input.KEY_ENTER: diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index 267a3f6e..476a62c7 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -70,9 +70,9 @@ import org.newdawn.slick.SlickException; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.transition.DelayedFadeOutTransition; +import org.newdawn.slick.state.transition.EasedFadeOutTransition; import org.newdawn.slick.state.transition.EmptyTransition; import org.newdawn.slick.state.transition.FadeInTransition; -import org.newdawn.slick.state.transition.FadeOutTransition; /** * "Game" state. @@ -767,7 +767,7 @@ public class Game extends BasicGameState { if (!unranked && !isReplay) ScoreDB.addScore(score); - game.enterState(Opsu.STATE_GAMERANKING, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_GAMERANKING, new EasedFadeOutTransition(), new FadeInTransition()); } return; } @@ -813,7 +813,7 @@ public class Game extends BasicGameState { } if (MusicController.isPlaying() || isLeadIn()) pauseTime = trackPosition; - game.enterState(Opsu.STATE_GAMEPAUSEMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_GAMEPAUSEMENU, new EmptyTransition(), new FadeInTransition()); } // drain health @@ -843,7 +843,7 @@ public class Game extends BasicGameState { // fade to pause menu game.enterState(Opsu.STATE_GAMEPAUSEMENU, new DelayedFadeOutTransition(Color.black, MUSIC_FADEOUT_TIME, MUSIC_FADEOUT_TIME - LOSE_FADEOUT_TIME), - new FadeInTransition(Color.black)); + new FadeInTransition()); } } } @@ -901,7 +901,7 @@ public class Game extends BasicGameState { } if (MusicController.isPlaying() || isLeadIn()) pauseTime = trackPosition; - game.enterState(Opsu.STATE_GAMEPAUSEMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_GAMEPAUSEMENU, new EmptyTransition(), new FadeInTransition()); break; case Input.KEY_SPACE: // skip intro @@ -1028,7 +1028,7 @@ public class Game extends BasicGameState { } if (MusicController.isPlaying() || isLeadIn()) pauseTime = trackPosition; - game.enterState(Opsu.STATE_GAMEPAUSEMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_GAMEPAUSEMENU, new EmptyTransition(), new FadeInTransition()); return; } diff --git a/src/itdelatrisu/opsu/states/GamePauseMenu.java b/src/itdelatrisu/opsu/states/GamePauseMenu.java index 048f993c..25447f47 100644 --- a/src/itdelatrisu/opsu/states/GamePauseMenu.java +++ b/src/itdelatrisu/opsu/states/GamePauseMenu.java @@ -38,7 +38,7 @@ import org.newdawn.slick.SlickException; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.transition.FadeInTransition; -import org.newdawn.slick.state.transition.FadeOutTransition; +import org.newdawn.slick.state.transition.EasedFadeOutTransition; /** * "Game Pause/Fail" state. @@ -128,7 +128,7 @@ public class GamePauseMenu extends BasicGameState { MusicController.playAt(MusicController.getBeatmap().previewTime, true); if (UI.getCursor().isBeatmapSkinned()) UI.getCursor().reset(); - game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EasedFadeOutTransition(), new FadeInTransition()); } else { SoundController.playSound(SoundEffect.MENUBACK); gameState.setRestart(Game.Restart.FALSE); @@ -178,7 +178,7 @@ public class GamePauseMenu extends BasicGameState { if (UI.getCursor().isBeatmapSkinned()) UI.getCursor().reset(); MusicController.setPitch(1.0f); - game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EasedFadeOutTransition(), new FadeInTransition()); } } diff --git a/src/itdelatrisu/opsu/states/GameRanking.java b/src/itdelatrisu/opsu/states/GameRanking.java index 1a0ac8ac..5ade7f2b 100644 --- a/src/itdelatrisu/opsu/states/GameRanking.java +++ b/src/itdelatrisu/opsu/states/GameRanking.java @@ -36,7 +36,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import org.lwjgl.opengl.Display; -import org.newdawn.slick.Color; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; @@ -45,7 +44,7 @@ import org.newdawn.slick.SlickException; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.transition.FadeInTransition; -import org.newdawn.slick.state.transition.FadeOutTransition; +import org.newdawn.slick.state.transition.EasedFadeOutTransition; import org.newdawn.slick.util.Log; /** @@ -207,7 +206,7 @@ public class GameRanking extends BasicGameState { Beatmap beatmap = MusicController.getBeatmap(); gameState.loadBeatmap(beatmap); SoundController.playSound(SoundEffect.MENUHIT); - game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_GAME, new EasedFadeOutTransition(), new FadeInTransition()); return; } } @@ -248,7 +247,7 @@ public class GameRanking extends BasicGameState { songMenu.resetGameDataOnLoad(); if (UI.getCursor().isBeatmapSkinned()) UI.getCursor().reset(); - game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EasedFadeOutTransition(), new FadeInTransition()); } /** diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index ba110cee..8eb78819 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -54,7 +54,7 @@ import org.newdawn.slick.SlickException; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.transition.FadeInTransition; -import org.newdawn.slick.state.transition.FadeOutTransition; +import org.newdawn.slick.state.transition.EasedFadeOutTransition; /** * "Main Menu" state. @@ -498,7 +498,7 @@ public class MainMenu extends BasicGameState { // downloads button actions if (downloadsButton.contains(x, y)) { SoundController.playSound(SoundEffect.MENUHIT); - game.enterState(Opsu.STATE_DOWNLOADSMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_DOWNLOADSMENU, new EasedFadeOutTransition(), new FadeInTransition()); return; } @@ -586,7 +586,7 @@ public class MainMenu extends BasicGameState { break; case Input.KEY_D: SoundController.playSound(SoundEffect.MENUHIT); - game.enterState(Opsu.STATE_DOWNLOADSMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_DOWNLOADSMENU, new EasedFadeOutTransition(), new FadeInTransition()); break; case Input.KEY_R: nextTrack(); @@ -671,6 +671,6 @@ public class MainMenu extends BasicGameState { ((DownloadsMenu) game.getState(Opsu.STATE_DOWNLOADSMENU)).notifyOnLoad("Download some beatmaps to get started!"); state = Opsu.STATE_DOWNLOADSMENU; } - game.enterState(state, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(state, new EasedFadeOutTransition(), new FadeInTransition()); } } diff --git a/src/itdelatrisu/opsu/states/OptionsMenu.java b/src/itdelatrisu/opsu/states/OptionsMenu.java index 4ceeaf33..1c621210 100644 --- a/src/itdelatrisu/opsu/states/OptionsMenu.java +++ b/src/itdelatrisu/opsu/states/OptionsMenu.java @@ -42,8 +42,8 @@ import org.newdawn.slick.Input; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; -import org.newdawn.slick.state.transition.EmptyTransition; import org.newdawn.slick.state.transition.FadeInTransition; +import org.newdawn.slick.state.transition.EmptyTransition; /** * "Game Options" state. @@ -297,7 +297,7 @@ public class OptionsMenu extends BasicGameState { // back if (UI.getBackButton().contains(x, y)) { SoundController.playSound(SoundEffect.MENUBACK); - game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); return; } @@ -375,7 +375,7 @@ public class OptionsMenu extends BasicGameState { switch (key) { case Input.KEY_ESCAPE: SoundController.playSound(SoundEffect.MENUBACK); - game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); break; case Input.KEY_F5: // restart application diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index 77b4e312..8c750c33 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -72,9 +72,9 @@ import org.newdawn.slick.SpriteSheet; import org.newdawn.slick.gui.TextField; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame; -import org.newdawn.slick.state.transition.EmptyTransition; import org.newdawn.slick.state.transition.FadeInTransition; -import org.newdawn.slick.state.transition.FadeOutTransition; +import org.newdawn.slick.state.transition.EasedFadeOutTransition; +import org.newdawn.slick.state.transition.EmptyTransition; /** * "Song Selection" state. @@ -773,7 +773,7 @@ public class SongMenu extends BasicGameState { if (UI.getBackButton().contains(x, y)) { SoundController.playSound(SoundEffect.MENUBACK); ((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset(); - game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_MAINMENU, new EasedFadeOutTransition(), new FadeInTransition()); return; } @@ -789,7 +789,7 @@ public class SongMenu extends BasicGameState { return; } else if (selectOptionsButton.contains(x, y)) { SoundController.playSound(SoundEffect.MENUHIT); - game.enterState(Opsu.STATE_OPTIONSMENU, new EmptyTransition(), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_OPTIONSMENU, new EmptyTransition(), new FadeInTransition()); return; } @@ -863,7 +863,7 @@ public class SongMenu extends BasicGameState { // view score GameData data = new GameData(focusScores[rank], container.getWidth(), container.getHeight()); ((GameRanking) game.getState(Opsu.STATE_GAMERANKING)).setGameData(data); - game.enterState(Opsu.STATE_GAMERANKING, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_GAMERANKING, new EasedFadeOutTransition(), new FadeInTransition()); } else { // score management ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.SCORE, focusScores[rank]); @@ -895,7 +895,7 @@ public class SongMenu extends BasicGameState { // return to main menu SoundController.playSound(SoundEffect.MENUBACK); ((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset(); - game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_MAINMENU, new EasedFadeOutTransition(), new FadeInTransition()); } break; case Input.KEY_F1: @@ -1611,6 +1611,6 @@ public class SongMenu extends BasicGameState { gameState.loadBeatmap(beatmap); gameState.setRestart(Game.Restart.NEW); gameState.setReplay(null); - game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + game.enterState(Opsu.STATE_GAME, new EasedFadeOutTransition(), new FadeInTransition()); } } diff --git a/src/org/newdawn/slick/state/transition/DelayedFadeOutTransition.java b/src/org/newdawn/slick/state/transition/DelayedFadeOutTransition.java index 231fe26d..b6f9b2db 100644 --- a/src/org/newdawn/slick/state/transition/DelayedFadeOutTransition.java +++ b/src/org/newdawn/slick/state/transition/DelayedFadeOutTransition.java @@ -39,6 +39,7 @@ public class DelayedFadeOutTransition implements Transition { * @param color The color we're going to fade out to * @param fadeTime The time it takes the fade to occur * @param delay The time before the fade starts (must be less than {@code fadeTime}) + * @throws IllegalArgumentException if {@code delay} is greater than {@code fadeTime} */ public DelayedFadeOutTransition(Color color, int fadeTime, int delay) { if (delay > fadeTime) diff --git a/src/org/newdawn/slick/state/transition/EasedFadeOutTransition.java b/src/org/newdawn/slick/state/transition/EasedFadeOutTransition.java new file mode 100644 index 00000000..8a904fd3 --- /dev/null +++ b/src/org/newdawn/slick/state/transition/EasedFadeOutTransition.java @@ -0,0 +1,83 @@ +package org.newdawn.slick.state.transition; + +import itdelatrisu.opsu.ui.animations.AnimationEquation; + +import org.newdawn.slick.Color; +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; +import org.newdawn.slick.state.GameState; +import org.newdawn.slick.state.StateBasedGame; + +/** + * A transition to fade out to a given colour using an easing function. + * + * @author kevin (base) + */ +public class EasedFadeOutTransition implements Transition { + /** The color to fade to */ + private final Color color; + /** The time it takes the fade to happen */ + private final int fadeTime; + /** The easing function */ + private final AnimationEquation eq; + /** The transition progress */ + private float t = 0f; + + /** + * Create a new eased fade out transition. + */ + public EasedFadeOutTransition() { this(Color.black, 500, AnimationEquation.OUT_QUART); } + + /** + * Create a new eased fade out transition. + * + * @param color The color we're going to fade out to + */ + public EasedFadeOutTransition(Color color) { this(color, 500, AnimationEquation.OUT_QUART); } + + /** + * Create a new eased fade out transition. + * + * @param color The color we're going to fade out to + * @param fadeTime The time it takes the fade to occur + */ + public EasedFadeOutTransition(Color color, int fadeTime) { this(color, fadeTime, AnimationEquation.OUT_QUART); } + + /** + * Create a new eased fade out transition. + * + * @param color The color we're going to fade out to + * @param fadeTime The time it takes the fade to occur + * @param eq The easing function to use + */ + public EasedFadeOutTransition(Color color, int fadeTime, AnimationEquation eq) { + this.color = new Color(color); + this.color.a = 0; + this.fadeTime = fadeTime; + this.eq = eq; + } + + @Override + public boolean isComplete() { return (color.a >= 1); } + + @Override + public void postRender(StateBasedGame game, GameContainer container, Graphics g) { + Color old = g.getColor(); + g.setColor(color); + g.fillRect(0, 0, container.getWidth() * 2, container.getHeight() * 2); + g.setColor(old); + } + + @Override + public void update(StateBasedGame game, GameContainer container, int delta) { + t += delta * (1.0f / fadeTime); + float alpha = t > 1f ? 1f : eq.calc(t); + color.a = alpha; + } + + @Override + public void preRender(StateBasedGame game, GameContainer container, Graphics g) {} + + @Override + public void init(GameState firstState, GameState secondState) {} +}