Nifty loading screen tutorial not working for me

Hi, I am nearly done with my game. I wanted to add a loading bar to the beginning of the game; However, I am not getting the desired results. I followed the tutorial, and everything works exactly as expected except the progress bar. It starts at 100% and stays at 100%.

Here is the code I am using:
[java]
public void update(float tpf)
{
if ( loading )
{
if (frameCount == 1)
{
Element element = nifty.getScreen(“load”).findElementByName(“loadingtext”);
textRenderer = element.getRenderer(TextRenderer.class);
}
app.loadGame(frameCount); //this method has a series of IF statements for each frameCount possibility.
frameCount++;

    }
}

public void setProgress(final float progress, String loadingText)
{
    
    int pixelWidth = (int) (MIN_WIDTH + ( (progressBarElement.getParent().getWidth() - MIN_WIDTH) * progress) );
    progressBarElement.setConstraintWidth(new SizeValue(pixelWidth + "px"));
    progressBarElement.getParent().layoutElements();

    textRenderer.setText(loadingText);
}

public void cleanup()
{


    app.getInputManager().setCursorVisible(false);
    app.getGuiViewPort().removeProcessor(niftyDisplay);
    
}

public void bind(Nifty nifty, Screen screen) 
{
    this.nifty = nifty;
    this.screen = screen;
    progressBarElement = nifty.getScreen("load").findElementByName("progressbar");
}

public void bind(Nifty nifty, Screen screen, Element elmnt, Properties prprts, Attributes atrbts)
{
    progressBarElement = elmnt.findElementByName("progressbar");
}

[/java]

[java]
Here is the Nifty XML:

<nifty>

<controlDefinition name = “loadingbar” controller = “jme3test.TestLoadingScreen”>
<image filename=“Interface/border.png” childLayout=“absolute”
imageMode=“resize:15,2,15,15,15,2,15,2,15,2,15,15”>
<image id=“progressbar” x=“0” y=“0” filename=“Interface/inner.png” width=“32px” height=“100%”
imageMode=“resize:15,2,15,15,15,2,15,2,15,2,15,15” />
</image>
</controlDefinition>

<screen id=“load” controller = “mygame.StartAppState”>

&lt;layer id="loadinglayer" childLayout="center" backgroundColor="#000000"&gt;
      
    &lt;panel id = "loadingpanel" childLayout="vertical" align="center" valign="center" height="32px" width="70%"&gt;
          
        &lt;control name="loadingbar" align="center" valign="center" width="100%" height="100%" /&gt;
            
        &lt;control id="loadingtext" name="label" align="center" text="                                                  "/&gt;
      
        
    &lt;/panel&gt;
   
&lt;/layer&gt;

</screen>

</nifty>

[/java]

have you put a breakpoint/print statement in setProgress, to see if it is being called with incrementing values? Just to make sure that it’s just not loading really fast, put a sleep statement in. Can we see snippets of your app.loadGame()?

[java]

public void loadGame(int frameCount)
{

    if (frameCount == 1)
    {
        layoutManager = new LayoutManager();
        layoutManager.setUsers(this, assetManager);//delete this, pass into constructor Main app, replace assetmanager. Check if still works.
        started.setProgress(.08f, "Loading Layout Manager...");
    }
    if (frameCount == 2)
    {
        viewPort.setBackgroundColor(new ColorRGBA(.7f, .8f, 1f, 1f) );  
        started.setProgress(.16f, "Loading Sky...");
    }
    if (frameCount == 3)
    {
        flyCam.setMoveSpeed( 0f );
        setUpKeys();
        started.setProgress(.24f, "Loading Input...");
    }
    if (frameCount == 4)
    {
        initParticles();
        started.setProgress(.32f, "Loading Particles...");
    }
    if (frameCount == 5)
    {         
        setUpScene();
        started.setProgress(.40f, "Loading Scene...");
    }
    if (frameCount == 6)
    {
        setUpLight();
        started.setProgress(.55f, "Lighting Scene...");  
    }
    if (frameCount == 7)
    {
        setUpCharacter();
        started.setProgress(.63f, "Preparing Character..."); 
    }
    if (frameCount == 8)
    {
        initHUD();
        started.setProgress(.71f, "Loading HUD..."); 
    }
    if (frameCount == 9)
    {
        layoutManager.generateGame();
        started.setProgress(.79f, "Generating Rooms...");
    }

[/java]

I will test out that breakpoint idea right now.

Alright, I guess I am not sure what a sleep statement is. Could you elaborate? It seems to be doing it incremementally when I call println(progress). The thing is, I tried commenting out the first 3 lines of the body of setProgress (so in theory the bar wouldn’t even change) and it still started at 100%. I think this may mean there is an issue with my nifty code.

Here is what setProgress looked like when I did this:

[java]

public void setProgress(final float progress, String loadingText)
{

// int pixelWidth = (int) (MIN_WIDTH + ( (progressBarElement.getParent().getWidth() – MIN_WIDTH) * progress) );
// progressBarElement.setConstraintWidth(new SizeValue(pixelWidth + “px”));
// progressBarElement.getParent().layoutElements();

    textRenderer.setText(loadingText);
}

[/java]

most likely yeh, where do you set up nifty?

It’s in XML. I posted the load screen in my first post I do believe. I may be understanding your question wrong though.

where do you setup nifty and your screen in code

[java]

public void initialize(AppStateManager stateManager, Application app)
{
super.initialize(stateManager, app);
this.app = (Main) app;
this.assetManager = app.getAssetManager();

    niftyDisplay = new NiftyJmeDisplay(
    assetManager, app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());
    nifty = niftyDisplay.getNifty();
    app.getGuiViewPort().addProcessor(niftyDisplay);
    nifty.fromXml("Interface/In-game Screens.xml", "start", this);
    
    app.getInputManager().setCursorVisible(true);
} [/java] 

And once start is clicked this method happens:

[java]
public void startGame()
{
app.getAudioManager().playAudioNode(“select”);
loading = true;
nifty.gotoScreen(“load”);
} [/java]