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”>
<layer id="loadinglayer" childLayout="center" backgroundColor="#000000">
<panel id = "loadingpanel" childLayout="vertical" align="center" valign="center" height="32px" width="70%">
<control name="loadingbar" align="center" valign="center" width="100%" height="100%" />
<control id="loadingtext" name="label" align="center" text=" "/>
</panel>
</layer>
</screen>
</nifty>
[/java]