LibGDX persist actors while switching screens?

一世执手 提交于 2019-12-11 19:04:04

问题


I'm making a game in LibGDX and I have a couple of menu screens using the scene2d ui. I have one MenuBaseScreen super class that sets up the default actors required for each screen. Then i have a MainMenu, Options etc screens that each inherit from MenuBaseScreen. In each of the screens there is a parallax background that keeps going from right to left. This parallax background gets instantiated in the MenuBaseScreen.

Now the problem with this is that each time I switch screen there is a quick lag because the background have to get re-instantiated and added to the stage again since each subclass calls the super constructor where all of this happens.

So I was wondering if there is a way to persist this image and its animation while switching screens?

Of course I could just replace all the actors except my background and just have one screen instead of many. But I think that approach is kind of clunky and makes for error prone code.

Thank you.


回答1:


Why not make the actors/components needed part of the MenuBaseScreen as static that are used in multiple screens. Also you might want to look at using the Screen interface already in libGDX with the Game class for your ApplicationListener class. More info here.



来源:https://stackoverflow.com/questions/23231029/libgdx-persist-actors-while-switching-screens

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!