LIBGDX: CREATING MULTIPLE STAGES DEGRADES PERFORMACE
While working on a game using the ever wonderful libgdx, I noticed slow performance when I was using two different Stages. One stage was the game HUD and the other served as a poorman's dialog.I didn't notice the choppy performance hiccups until after I called draw on the second stage then returned back to the original HUD stage.I had something like the following (WARNING: pseudocode):
Stage hud = new Stage();
Stage dlg = new Stage();
...
hud.addActor(widget1);
hud.addActor(widget2);
dlg.addActor(widget3);
...
void render() {
if (show == HUD) {
hud.draw();
} else {
dlg.draw();
}
}
Stage ui = new Stage();
Vector hud = new Vector();
hud.add(widget1);
hud.add(widget2);
Vector dlg = new Vector();
dlg.add(widget3);
...// Call show() when you want to switch context
void show(what) {
ui.clear();
Vector widges = hud;
if (what == DLG) {
widges = dlg;
}
Iterator iter = widges.iterator();
while (iter.hasNext()) {
ui.addActor(iter.next());
}
}void render() {
ui.draw();
}
That cleared up my performance trouble.Find out more about libgdx at Badlogic Games