1

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:

  1. Stream a resource to reduce loading time as the wiki suggests.
  2. Load only selected resources and load more when changing states (load the game music only when entering game state, etc.).
2mac
  • 1,609
  • 5
  • 20
  • 35

1 Answers1

1

I accidentally came across the answer.

public void init(GameContainer gc, StateBasedGame game) throws SlickException{
    try{
        theme[0] = new Music("path/to/theme1.ogg",true);
    }catch (Exception e){
        e.printStackTrace;
    }
}

Adding true after the file reference indicates that you want to stream the audio.

2mac
  • 1,609
  • 5
  • 20
  • 35