To make the button can be interacted we have to keep in mind is that the Stage are InputProcessor. And you say “can not be”, but, the Stage are InputAdapter type, which in turn are InputProcessor type. That means that what we saw makes a lot of videos, by the way, to make a InputProcessor and assign it to the input we can do with the Stage. To do this I will come to show, because it has to be on show only for run when we will display the screen, and run Gdx.input.setInputProcessor (), and passed the Stage to a InputProcessor and is associated. The advantage of this is that all processes and events occurring at the entrance to the actors, as when we clicked on an actor. When we go to remove the screen Acordaros stop using the Stage as InputProcessor, because if not the things can get bad because we do not see the Stage but nevertheless still trying entrance and that may give some problems.
From that moment you see, when you click on my button, it will work properly and be able to do things with him. Just not much to do, nothing happens. We can throw us hours but do not click. That’s because you have to give a performance, and I have to fill the addCaptureListener method, which is used to add a listener it runs when we have “changed” somehow the actor. This code is simply make a copy and paste of these two classes and already it is overwritten the changed () method which is executed when we click the button. We can take this time to ask our game screen game and everyone happy. The only problem is how I really do. We need something that allows us to change from screen to screen, and for that I will come to MainGame, and record each of the screens that we have created in our game. For example … I will make public because it is not worth, to have a pointer to which access GameOverScreen or GameScreen … let’s add another pointer to GameOverScreen.
Now what I do is that GameScreen GameScreen is new and GameOverScreen is new GameOverScreen. And now finally instead of calling a new screen setScreen I do with GAMEOVER. How could we do this in a nice way? We could create a list of screens or a map that associates a string with a Screen and so do something like GetScreen ( “game”) or things like that. O constants. There are many ways to do this, what you can think of. This is not the best way but it is a so that works and so we do not get into trouble now, but there are many ways to fix this, using little numbers to identify each screen, constants, what you can think of.
Yes now. We want when we hit the button to change to the game screen. For that, Game, such as screen-based game has a method called setScreen you may already know it, but it’s public, we can call at any time while you say the screen I want to use it and I have it ready. The only but is that as Game is used within an anonymous class, it must be the end, how it is done by Java, which requires that a variable is final if we use an anonymous class which is inside, but good. Ignoring that detail, If now pulse. It serves to switch the screen. The only thing left is to make when you lose again GameOver screen, so what we’ll do is that the following when you die, in the GameScreen, occurs a little: this is the … what is the method that runs when you crash? Yes.
This. Which prints a GameOver. I’ll do that when you die, after a second or two seconds go to the GameOver screen. To do what I have to do is add to stage an action It used to make animations. The actions are of many types: be an action to encourage the movement of something or to encourage rotation, or even scale it, or to run code, and that’s what I want: I will first apply an action to delay call a moment you wait, and then I’ll make a run for the code that lets me switch the screen to run.
And I want action run after another will use the action sequence, which is an action of action. I can pass him two actions to run next to each other. I want the action to be expected to run, so you can wait one second and a half. And then I want you can jump to the GameOver screen, so I overwrite the method you ask me to overwrite and simply put game.setScreen (game.gameOverScreen).
At that moment, when we die, a second and a half later, we skip the GameOver screen. Very good. The only thing left is to repeat this same step to build a screen start like we just did. Do not going to lose anything..
As found on Youtube