BEEPS AND BLIPS FROM OUTERSPACE
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();   } }

After seeing the problem, I had a suspicion the performance degrades when swapping between Stages and I still am not sure why it does so.  At any rate, I fixed the problem by using only one Stage then adding and removing Actors when needed.So, the code ended up something like this: 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
POSTED • 2011-12-21 11:16:07 • CATEGORY • ENGINEERING • TAGS • GAMELIBGDXPERFORMANCE
comments powered by Disqus