# How do I switch between the game screen and score screen without redrawing everything?

I'm working on a multiplayer game in Libgdx and want to display the scores of say, the top 10 players on the map. The player should be able to checking the scores at any point during the game and return to the game screen (with themselves in the same location they were at earlier), much like pressing Tab during a game of Counter Strike displays the scores.

Changing the screen to the score screen is simple enough using setscreen, but how can I return to the previous view without calling a setscreen on the game screen and rendering everything all over again?

• There's probably no real way around that (note that I've never used libdgx so far). You'll typically have to redraw everything, unless you store the output in a render texture, but that wouldn't make any sense here IMO. Things like that are typically organized using a finite state machine, possibly in combination with a stack. Whatever is on top of your stack is updated/rendered. To go back to a previous screen, you just pop the top. – Mario Aug 9 '14 at 13:28
• What is setScreen? Is that a libGDX function or your own function? – ashes999 Aug 9 '14 at 23:58
• setScreen is a libgdx function used to change between screens. – dreadnought303 Aug 10 '14 at 14:16

Then make something like:

enum gameState = { PLAYING = 0, MAINMENU = 1, SCOREBOARD = 2, ... }

if(Player.action = PLAYING)
{
... do stuff ...
}
{
... do stuff ...
}
else if(Player.action = SCOREBOARD)
{
... do stuff ...
}


And about the rendering. It's hard to get around that.

• Rather than comparing the value of Player.action you're assigning it. Plus I'd use switch() rather than multiple instances of if() even if it's just for readability. – Mario Aug 9 '14 at 13:48
• Well, you could do switch. But the point is. You could give the player an INT action. I do it this way. And it works great. – ADG Developing Aug 9 '14 at 14:07

you have to create some table, whatever. that will be displayed on the current screen.

the values is the question important here. You have to call from where? got it?

if you saved the values on SQLite you can make a method that load the top scores.

you can read something about multiple input processors to alternate inputs when the user

click on score button (active scoreinputprocessor) and reactive gameinputprocessor when close score.

i did it just like this. i did got nice results.

REFERENCE:

Ok man, the files that you have to read to learn and use your creativity:

Multiple processors: InputMultiplexer

Table: Table Layout

EXAMPLE

• This doesn't seem to really address the question at all. – user1430 Aug 10 '14 at 17:41
• On the contrary, this is probably the most appropriate answer for what the OP wants, especially in libGDX. Using a scene2d-ui Table will allow an overlay on top of the current screen without having to perform a setScreen(). Hence, the state of the game, including all the elements can remain while the score overlay is painted over the screen. The use of the multiplexer will enable touches to be sent to the score overlay without affecting the game underneath. Upon closing the overlay, the game can be resumed as per normal by in registering the overlay as an input processor. – midasmax Aug 10 '14 at 17:59
• Perhaps, but I don't think this answer explains, to the asker, what actually needs to be done in a useful and coherent fashion. Your explanation is much better -- perhaps you should post it as an answer or submit a clarifying edit. – user1430 Aug 10 '14 at 18:34