Sorry to dig up a dead thread, I just thought this was important for others who might stumble upon this thread through internet searches (like me).
First:
cghislai wrote:
Unfortunately, you can't use threads to load your assets. It will throw an exception, saying that all initialization stuff should be done in the Slick thread in the init() or update() methods.
This is incorrect. I use a separate thread to load my Slick2D assets just fine by doing something like this:
Code:
// We are forcefully loading resources. Disable deferred loading.
LoadingList.setDeferredLoading( false );
try {
// Get Drawable context for this thread.
Drawable drawable = Display.getDrawable();
SharedDrawable sharedDrawable = new SharedDrawable( drawable );
sharedDrawable.makeCurrent();
// Load images or whatever here.
new Image(path);
// Release Drawable from this thread.
sharedDrawable.releaseContext();
sharedDrawable.destroy();
}
catch( LWJGLException e )
{
log.error( e );
}
Second:
I have a loading screen state that basically works like this:
- On enter, read an XML file with details about all the needed game resources (images, sounds, etc)
- Feed data into resource manager which returns an object i can use for checking on the loading status
- On the loading screen state, listen for updates in the status object and update the display accordingly.
- When the status object says the resources are done loading, switch to your next state like normal.
- During the loading screen's leave method I do some extra post-loading stuff in another thread such as warming up the Groovy engine because that can take 3-4 seconds on first load.
Hope that gives others some ideas! Maybe I'll do a tutorial on the Slick wiki if I'm bored or someone prods me about it.
Good luck!