Libgdx - How to pass a variable value from one screen to another?

走远了吗. 提交于 2019-12-12 16:23:49

问题


I'm creating a game for Android phones and I need a player number from screen where I select it to another screen where I use it for something else. On screen where I select specific number, method for returning number of players works perfectly but when I use that method on another screen it returns zero. I select number (picture for specific number) from ScrollPane. When I change screen I clear screen and draw new one as usual. So my question is how can I save that value and return it even when screen has changed?


回答1:


Pass it through the constructor of the other screen

game.setScreen(new PlayScreen(var));


来源:https://stackoverflow.com/questions/42176696/libgdx-how-to-pass-a-variable-value-from-one-screen-to-another

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