I'm writing a game using the Slick2D library. I recently added a loading screen using deferred loading. I use the Music class to load OGG files to be used as music. These take an excessive amount of time to load. I looked on the wiki for more information on deferred loading. I found:
No one resource should take so long to load that it keeps the screen from refreshing for a significant amount of time (if it does, then the resource should probably be streamed anyway :)).
So I altered my menu class as follows (this is just an example and I'm leaving out quite a bit):
public class MainMenu extends BasicGameState{
private Music[] theme = new Music[1];
public void init(GameContainer gameContainer, StateBasedGame stateBasedGame) throws SlickException{
InputStream[] musicStream = {ResourceLoader.getResourceAsStream("/path/to/theme1.ogg")}
try{
theme[0] = new Music(musicStream[0],"path/to/theme1.ogg");
}catch (Exception e){
e.printStackTrace;
}
}
(rest of class)
The music array is an array of org.newdawn.slick.Music
So I thought I'd done what would reduce loading time. However, when loading, it took just as long, but instead of showing a file as the current resource, it showed the stream.
I'd like to know how to do one or both of the following:
- Stream a resource to reduce loading time as the wiki suggests.
- Load only selected resources and load more when changing states (load the game music only when entering game state, etc.).