The first thing I should mention is that you haven't stated your symptoms. I may be able to help, but I could offer more help if you told me whether the splash screen was never appearing, alwayse there, or fading at the wrong time.
the problem likely lies within the following lines:
Code:
if(alpha < 1) {
alpha += alpha + 0.000001f;
}
this code should double the alpha and add a very small number to it each update.
this means that at 60fps, the image will have an alpha of around 0.04 (barely invisible) after the first
15 frames, and by 20 frames, be fully opaque, making it appear to pop into existence in 1/12 of a second
(instantly).
to try to offer a solution, the following, untested code should approximately do what you want:
Code:
private int alphaTimerMs=0;
private float alpha=0f;
public static final int FADE_IN_TIME_MS=500;//fade in for 1/2 second
public static final int LEAVE_TIME_MS=3000;//end the state after 3 seconds
public SplashScreen(int state) {}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
splashScreen = new Image("/res/splashscreen.png");
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) {
Color color = new Color(1f, 1f, 1f, alpha);
splashScreen.draw(0, 0, color);
//I usually use:
//splashScreen.setAlpha(alpha);
//splashScreen.draw();
//but your method should do the exact same thing
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) {
alphaTimerMs+=delta;
//usually, alpha will need to be one
alpha=1;
//but if FADE_IN_TIME_MS milliseconds have not passed,
//alpha should be set to a fraction
if (alphaTimerMs<FADE_IN_TIME_MS){
//this next line will compute the alpha float. In order to divide as a float
//one of the parts will need to be cast to a float. I chose alphaTimerMs
alpha=((float)alphaTimerMs)/FADE_IN_TIME_MS;
}
//finally, if LEAVE_TIME_MS milliseconds have passed,
//go to the next state
if (alphaTimerMs<FADE_IN_TIME_MS){
sbg.enterState(sbg.STATE_MAIN_MENU);
}
}