RPC actually doesnt have a resource loader at all (yet), I created a “transition” class that pops the load screen up while enter() is running and loading all the state’s crap.
package rpc;
import java.util.WeakHashMap;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
import rpc.launcher.Game;
public class TransitionModule {
private static WeakHashMap<Integer, TransitionModule> stateInstance = new WeakHashMap<Integer, TransitionModule>();
FontModule font;
private GameContainer gc;
private Color fade = new Color(0,0,0,255);
private boolean fadeIn = false;
private boolean fadeOut = false;
private boolean fadeOutComplete = false;
private boolean fadeOutCheck = false;
private boolean fadeOnly = false;
private int fadeAmount = 0;
private boolean controlLockout = false;
private int stateID = 0;
private int fadeOutSpeed, fadeInSpeed = 25;
public TransitionModule(){stateInstance.put(Game.getCS(), this);}
public void initController(GameContainer gc) throws SlickException{
font = FontModule.getState();
this.gc = gc;
}
public void enter(int i){
fadeInSpeed = i;
fadeAmount = 300;
fadeIn = true;
}
public void startTransition(String state, int o, boolean fade){
fadeOutSpeed = o;
fadeOut = true;
if (fade){this.fadeOnly = true;}
if (state.equals("splashState")){stateID = 0;}
if (state.equals("mainMenuState")){stateID = 1;}
if (state.equals("mapEditorState")){stateID = 2;}
if (state.equals("playState")){stateID = 3;}
if (state.equals("exit")){stateID = 10;}
}
public void update(StateBasedGame sbg){
// Start fade
if (fadeOut){
controlLockout = true;
fadeAmount += fadeOutSpeed;
fade = new Color(0,0,0,fadeAmount);
}
// Detect fade is completed.
if ((fadeOut) && (fadeAmount >= 300)){
fadeOut = false;
fadeOutComplete = true;
if (fadeOnly){fadeOutCheck = true;}
}
// Fade in slowly
if (fadeIn){
controlLockout = true;
fadeAmount -= fadeInSpeed;
fade = new Color(0,0,0,fadeAmount);
}
if ((fadeIn) && (fadeAmount <= 0)){
controlLockout = false;
fadeIn = false;
fadeAmount = 0;
}
// Exit state, reset FadeOutComplete flag.
if (fadeOutComplete){
fadeOutComplete = false;
fadeAmount = 0;
controlLockout = false;
if (!fadeOnly){
if (stateID == 10){
gc.exit();
}else{
Game.setCS(stateID);
sbg.enterState(stateID);
}
}
fadeOnly = false;
}
}
public void render(Graphics g){
int displayWidth = Game.getInterfaceWidth();
int displayHeight = Game.getInterfaceHeight();
g.setColor(fade);
g.fillRect(-16,-16,displayWidth+32,displayHeight+32);
if (fade.a >= 1.0)
font.drawStringCentered(displayWidth/2,displayHeight/2, "Loading", 0, 255, 0, 3);
}
public boolean getControlLockout(){return controlLockout;}
public boolean getFadeOutCheck(){return fadeOutCheck;}
public static TransitionModule getState(){return stateInstance.get(Game.getCS());}
public static void removeState(){stateInstance.remove(Game.getCS());}
}
To clarify though, this is totally not the accepted practice. I just have not written a proper resource loader yet. But I use this class’s startTransition() to flip between states, it’ll fade out, “freeze” on the loading screen and then once enter() finishes eject you into whatever state you requested. Note that this TransitionModule object must be loaded in every single state to function correctly.
If you have a low, low load time (less than 3-4 seconds) this method works great though, since a resource loader is a bit overkill if you can almost load everything on the fly and you just want a little message to popup so people don’t think the game is frozen.