LIBGDX para Android – Tutorial 39 – Pantalla Game Over – How to make games Android

September 22, 2019

Right now as you see our game works, but there is no feedback to tell us that we have lost: the display will show an Over Game, but it is not a Game Over we see on screen, we see it in the console, because that game over there. It would be nice to have a way to tell us the game we have lost so that it is clear and that until there is a button to restart the game because now you no. I will create a screen secondary after this which I will call Game Over it will display the message and a button to return to the main screen. I’ll create a new screen as we have seen so far called GameOverScreen quietly, and this screen will show a button and a message put Game Over. The message I have it designed, is this picture, but what about the button? I mean, Scene2D has a module called Scene2D UI, which serves to create user interfaces. They are actors, and are typical elements of a user interface such as buttons, text labels, checkboxes, which you can think of. By Scene2D UI we can add these things without having to reinvent the wheel. We just need a way to give style. I use a skin but We can do this manually with styles. I’ll use a skin and it will use the official skin of libgdx will find in the repository, which is in the description of this video. The mission of the skin is to include the resources of the different UI widgets using Scene2D. Here you see I have the resources of the buttons, dropdown, checkboxes, less mases … pressing the buttons and change the number. He has letters to create letters. Who will cut this? Libgdx cuts already assuming we use the Skin class. I create the GameOverScreen, of BaseScreen type. You will have a Stage, but it will not have anything else. If anything, Skin to represent the style, an image to represent the GameOver, and will have a TEXTBUTTON which is the class which it deals with creating a button that can be pressed text even. I think the Stage. I think the Skin, I need to use the builder Skin, I pass the FileHandle my skin file, which is ending in .json. I pass as a FileHandle: Gdx.files.internal () to indicate that we want use an internal file in the assets folder. He deals with translating this and obtain the necessary resources, so only load the main already know how access to everything, nothing happens. Now what I do is create my image GameOver, for what the MainGame have put a load on the Manager, to GameOver. So I write to GameOver is a new Image, texture and say I want to use this image. UI Scene2D images show a texture as an actor, so it can be moved and manipulated. They are very versatile, really. I say Game.Manager.Get (GameOver.png), and complains because until it assigned to a variable can not know if it’s a Texture or something else, so I’ll pass a parameter to force the Manager to be of a whole class, for example Texture.class. Thus when making the imports, it’s a texture within this method and leaves as texture, why not give problems. Finally I create the button with a new TEXTBUTTON. As the first parameter, I pass the text label as the second parameter and the skin. Now what I’m going to do is, in the show (), show this. I simply put on the screen in a particular position, as gameOver.setPosition (). This I can do here in the constructor, because as always is going to be on the same site, and the horizontal half. As for retry, I give a size to 200×100 button to make it big, and I’ll put in the position (220.50), so that it is centered. No need to show because as I have it all done except add, nothing else happens. Just in case I need a dispose () to do a dispose () on the Stage. The GameOver not disposea, because the texture is below. As to render, yes, what I need it is to render it on the Stage, so I unashamedly copied the code used to clear the screen, because I do not remember the antics and now call stage.act () and stage.draw (). And you see that to make it so that the button has I do behavior that is updated. Finally, I replace momentarily GameScreen by GameOverScreen, and if I run see the result. It is not centered horizontally as expected, just because I wrong here. This is … if you want to center it, you put in half the width of the screen, least half the width of the texture. You should now look better. Now it works well. Though if now I try to click the button … not listen to me. Why? Because I have to make Scene2D and entry Stage to try clicking on the button to control it. We’ll see how to do this and end this little screen.

Leave a Reply

Your email address will not be published. Required fields are marked *