Hey guys!
After passing from 3.0 to 3.1 I noticed that my game would get slower and slower as time went by. After a whille of searching I noticed it was my active HUD that was causing the problem.
What I do for my hud is rebuild my screen every frame so that I can have health bars on npcs and stuff.
In 3.0 this worked flawlessly but on 3.1 it caused the frametime to go up considerably. Starts off at 320 fps and end up at 3 fps after about 2 min.
This is how I refresh my HUD screen:
public void Refresh(){
String s = getActiveScreen();
if(s.equals("")) return;
ScreenFactory.buildScreen(s, nifty);
nifty.gotoScreen(s);
}
public String getActiveScreen(){
if(nifty == null) return "";
Screen screen = nifty.getCurrentScreen();
if(screen == null) return "";
String ID = screen.getScreenId();
return ID;
}
If this is not the most elegant way to do this, please direct me to an example of an active HUD (hud that will change 60 times per second) that works?
Edit: I also noticed that when the fps is down to 3, switching to another non-active screen by doing a
nifty.removeScreen(getActiveScreen());
makes the fps go all the way back up. If I then go back to my active HUD it resumes at 3 fps.
Itâs like if switching to a new screen does not free resources of the previous screen like it used to.