Hi, in my game i extend the BaseApplet class.
I've had a look at the testloadinggamestate java code and implemented it in my game.
what basicly happens is that both gamestates (maingame and loadinggamestate) start at the same time, after initGame has finished loading all the resources…
How can i make the LoadingGameState appear while i really load the game?(while initGame is happening)
@Override
public void start()
{
super.start();
// Create the GameStateManager
GameStateManager.create();
}
@Override
protected void initGame()
{
//do loading and stuff
loadGameStates();
initRPGGame();
}
private void loadGameStates()
{
//create the main game state and attach it to the gamestate manager
mainGameState = new RPGGameState(this);
GameStateManager.getInstance().attachChild(mainGameState);
mainGameState.setActive(false);
//set loading state
loadingGameState = new LoadingGameState();
GameStateManager.getInstance().attachChild(loadingGameState);
loadingGameState.setActive(true);
GameTaskQueueManager.getManager().update(new Callable<Void>(){
public Void call() throws Exception {
// Create LoadingGameState and enable
final LoadingGameState loading = new LoadingGameState();
GameStateManager.getInstance().attachChild(loading);
loading.setActive(true);
GameTaskQueueManager.getManager().update(new LoadingTask(loading, 0));
return null;
}
});
}
private void initRPGGame()
{
//main scene node
rootNode = new Node("root");
//create the Z-buffer
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
rootNode.setRenderState(buf);
//GUI
gui = new RPGGUI(displayParent, display.getRenderer(), rootNode );
//initialize scene
createBasicLight();
createTerrain();
createSkyBox();
createPlayer();
initCharacterPosition();
//update scene for rendering
rootNode.updateGeometricState(0f, true);
rootNode.updateRenderState();
//set mouse input
initMouseCursor();
initKeyboardInput();
//enable the maingamestate
mainGameState.setActive(true);
@Override
protected void update(float interpolation) {
// Execute updateQueue item
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.UPDATE).execute();
// Update the GameStates
GameStateManager.getInstance().update(interpolation);
}
@Override
protected void render(float tpf) {
display.getRenderer().clearBuffers();
// Execute renderQueue item
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).execute();
// Render the GameStates
GameStateManager.getInstance().render(tpf);
}
class LoadingTask implements Callable<Void> {
private final LoadingGameState loading;
private final int progress;
public LoadingTask(LoadingGameState loading, int progress) {
super();
this.loading = loading;
this.progress = progress;
}
public Void call() throws Exception {
String status;
if (progress == 100) {
status = "I'm Finished!";
} else if (progress > 80) {
status = "Almost There!";
} else if (progress > 70) {
status = "Loading Something Extremely Useful";
} else if (progress > 50) {
status = "More Than Half-Way There!";
} else if (progress > 20) {
status = "Loading Something That You Probably Won't Care About";
} else {
status = "Started Loading";
}
Thread.sleep(100);
loading.setProgress(progress / 100.0f, status);
if (progress < 100) {
GameTaskQueueManager.getManager().update(new LoadingTask(loading, progress + 1));
}
return null;
}
}