Nifty - ScreenController.onAfterStartScreen() :roll:

I’m trying to figure out how to do things after the screen is started, in other words, after the elements are rendered on screen. The ScreenController.onStartScreen() doesn’t do what I’m wanting, it is called before the elements are rendered. I have a progress bar in my screen, and I’m trying to make the progress bar starts after the screen is started, otherwise, the things will be loaded but the progress bar won’t be rendered :/. Any ideas?

are you using the boolean load=true?

if you click a button run a void like:

[java]public void load() {



in the update():[java]if(load==true){<map,player… erverythink else what you want to load>




erverything from the normal update loop


but can you poste your code if that dosn’t help you?

...if you click a button run a void like:...

It's the problem. The start screen have just a progress bar, no buttons. The progress bar have to be started automatically. Btw, it's alreay have a load var. It seems be an easy thing, but it's not. I think it's almost impossible. The start screen code is this :

* To change this template, choose Tools | Templates
* and open the template in the editor.
package rhythmgame.nifty.control.screen;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import rhythmgame.nifty.control.progressbar.ProgressBar;
import rhythmgame.nifty.control.progressbar.ProgressBarControl;

* @author Glauco Márdano
public class StartScreenControl extends RhythmGameScreenController {

private ProgressBar loadingBar;
private boolean load;

public void bind(Nifty nifty, Screen screen) {
super.bind(nifty, screen);
loadingBar = screen.findControl("startLoadingBar", ProgressBarControl.class);

public void onStartScreen() {

public void loadStuffs() {
load = true;

public void update(float tpf) {
if (load) {
load = false;

<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<!-- start screen -->
<!-- +++++++++++++++++++++++++++++++++++++++ -->
<useStyles filename="Interface/Styles/styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<useControls filename="Interface/Controls/controls.xml" />
<screen id="startScreen" controller="rhythmgame.nifty.control.screen.StartScreenControl">
<layer id="startLoadingLayer" childLayout="horizontal">
<panel height="10%"/>
<panel id = "startLoadingPanel" childLayout="vertical" align="center" valign="center" height="32px" width="80%">
<control image="Interface/Skins/ProgressBar/inner-orange.png" id="startLoadingBar" name="progressBar" align="center" valign="center" width="100%" height="100%" progress="0f" direction="horizontal" progresstext=""/>
<panel height="10%"/>

do you think some thing like wait 1 second before loadstuff(); will work?

edit: do you need the progressbar? long loading time?

It looks nifty isn’t run in another thread, then if I use wait() it’ll stop both loadStuffs() and the nifty itself, then it will do nothing. The only way to use wait() is calling it in another thread I think, but I don’t wanna to use any threads on this stage. It’s not needed. Also, it’s a poor solution.

I think its almost impossible

Also, its a poor solution.

and you can use a tiner to wait one second

loadtimer = loadtimer + tpf;

I know, I use Timer in-game to synchronize the sound with the move bars, but risking a time is not a good approach. Also, who will garantee that the screen will be started in 1 second :roll:? It might takes more than expected. It might be a solution, but I don’t like it.

ok, i don’t have any other solutions at the moment, but i will post it when i find some thing :slight_smile: and good luck with your game!

1 Like

Thanks, I really appreciate your help. Good luck too ;).

1 Like

When you display the screen, you call something like fromXML or gotoScreen in another class, your main class probably.

This method returns the moment the screen is displayed.

You can use this by calling a method like startProgressBar or something right after your call to fromXML.

1 Like

your doing your loading and rendering in the same frame, if you wait a frame before doing the loading you should see your Progress bar screen first.

This might help

1 Like

@ractoc: Hmmm. Yeah, it really makes sense, starting the progress bar out of the screen controller and after it’s displayed might works, I didn’t try it yet. I’ll try it when I get home, thanks!

@wezrule: Yeah. I already read that page, and I should do how it does, by loading the stuffs out of the screen controller. I’ll try it, thanks!

No sucess too. I did it in simpleInitApp():





But the loadStuffs() method is still being called before the screen is displayed. I tried to go to the start screen in simpleInitApp() method and when the app starts I call loadStuffs() in simpleUpdate() too, but it does the same thing. As I said before, it seems be a easy thing to do, but it isn’t. Anyway, thanks for the helps.

If both of those calls are on the same thread then of course you will never see the screen.

You are basically saying:

-hey, nifty, goto a screen when you get a chance

-in the mean time, let me load this stuff blocking the thread that would update you

When you block the render thread, nothing gets rendered.

1 Like

hmmmmmmm. Yeah! The render thread xD. Then I’ll try to run the loadStuffs in another thread.

@pspeed: Thank you again! Your helps with threads are being very useful ;).

Hi all,

I have the same issue with the loading screen.

Could you just tell me what you call “blocking the rendre thread” ?

Is it to render nothing until the gui is displayed ?

Thank for your help.

Thank for the link but I know how render loop works.

My question was to know if he solved the issue by setting timer or thread stuff.

For me it is solved as I used timer to let the time to Nifty to display its contents.

Also thank for your quick reply.