Slick Forums

Discuss the Slick 2D Library
It is currently Thu Apr 17, 2014 9:22 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: A load screen (Resolved)
PostPosted: Thu Mar 24, 2011 10:13 pm 
Offline

Joined: Mon Mar 21, 2011 4:22 pm
Posts: 32
Location: United States
Hi back again with yet another question! Is there any possible to have a loading screen or a splash screen when your game is loading everything? I have a splash screen state before I actually enter my game state but it seems to load everything before the splash screen starts. So the splash screen appears for a nanosecond and disappears. Is there anyway around this so the user know's the game is loading? My game takes about 3 - 4 seconds to start up and is bound to get longer. Any help is appreciated! Thanks!


Last edited by Azulon on Fri Mar 25, 2011 1:34 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 24, 2011 10:58 pm 
Offline
Regular

Joined: Tue Mar 03, 2009 11:53 pm
Posts: 123
You can do like this:
You just load the splash screen and display it. After a while (one update/render loop is enough), you start to load the other assets. so even if the software freezes a little while loading, there's something on the screen. Basically, you don't load everything in the init but elsewhere.
Others more involved methods include the use of threads.

ciao!

_________________
Carotinho


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2011 1:30 am 
Offline

Joined: Mon Mar 21, 2011 4:22 pm
Posts: 32
Location: United States
That's the thing. I load up the splash screen before I load anything else and it still takes 4 seconds to display the splash screen. Then the splash screen literally just flashes and is gone.'

EDIT:

Actually just found a really easy fix. I load everything up under enter instead of init. Thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2011 4:56 pm 
Offline
Oldbie
User avatar

Joined: Fri Jul 20, 2007 9:25 am
Posts: 410
Location: Croatia
Azulon wrote:
Actually just found a really easy fix. I load everything up under enter instead of init. Thanks!!


that's not desirable, enter() is called every time that state is entered, so multiple times possibly.

What you need is deferred loading. You delay loading of everything until you want to load it, it's quite simple, there are examples also (wiki link?).


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2011 9:35 pm 
Offline

Joined: Thu Apr 21, 2011 2:32 pm
Posts: 45
Or, as Carotinho said, and as i did in i hate robots, move all your loading stuff in some other public method. In your loading state, once it has rendered once, load everything in the update method then switch state.

If you want to display some progress, use steps, something like

Code:
update(...) {
switch (step) {
 case 0:
  break;
 case 1:
  loadMusic();
  break;
 case 2:
  loadGraphics();
  break;
 ...
}
step++
}


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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 28, 2011 10:19 am 
Offline
Regular

Joined: Tue Mar 03, 2009 11:53 pm
Posts: 123
Hi.

Exceptions when loading assets outside the main thread is true for OpenGL-related materials, that is, images. Sounds etc. can be loaded smoothly in another thread.
If you want to load images in another thread, you should load them in system memory using some java method (which I don't remember right now) and then, when the bytebuffer is ready, raise a flag that makes the main OpenGL thread to actually create a texture out of those bytes. I've succesfully done that.

ciao!

_________________
Carotinho


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 28, 2011 3:37 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
The Slick test cases contain an example for deferred loading which is already built in with Slick.

https://bob.newdawnsoftware.com/repos/slick/trunk/Slick/src/org/newdawn/slick/tests/DeferredLoadingTest.java

Hope that helps,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2011 2:22 pm 
Offline

Joined: Thu Nov 18, 2010 4:04 pm
Posts: 24
Location: France
I've made a loading screen like this:
1) I created a Loading game state. When I start the game, I call init() only for the Loading state.
2) Loading.init() opens the directory, gathers the file paths/names in an array and returns the numbers of files to load.
3) I enter the Loading game state and the Loading.update() loop.
4) My update() method loads files one by one. This will return the numbers of files loaded, and I can display it in Loading.render().
5) Once all my files are loaded, I call init() for all the other game states.
6) I enter the Menu game stats. Finished.


Top
 Profile  
 
PostPosted: Thu Oct 04, 2012 5:17 am 
Offline

Joined: Mon Sep 12, 2011 4:56 pm
Posts: 8
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group