42 videos
238 minutes
From the moment we start to create the kind of game to create the Stage. I'm going to do as a new class that I will MainGameScreen call, which will extend to BaseScreen. At the moment only going to be a screen but this is a guarantee for the future because then we will want to have adjustments, we will want to have options, because maybe not everyone likes this Joe, so we will be able to put several joes,
or maybe not everyone likes music. As we will have to put multiple displays also, when before we do to correct then less code, the better. Now, this class will force me to pass the game itself as a parameter, so it does not matter: when you instantiate this MainGameScreen I must also tell the Game which it is associated, but what good is that from this moment, let's say I want to make a call to show
and I want to load a thing or do anything, I can do game.setScreen and tell you what the screen for which will change the game. When you press Back, we tell returns to the screen from the Start menu or when we go back button UI Scene2D we say go to another screen. We have everything to our liking. Let's see how we can do to work with Scene2D. As I spoke in the introduction, Scene2D is characterized by a stage, a Stage,
and the Stage is the place where we put the actors, who are each of the characters or elements of our game. The first thing we to do is create the Stage, because if not few players will be able to enter. And the Stage is particular because we have to draw, load ... so I'll create a Stage directly as a field, because I'm going to use in many ways: I must remove their resources (you know that
there is a SpriteBatch inside), I draw ... the simplest is to 'Stage Stage = new ()' so that the hide () can do Stage.dispose (). Some will ask because I get into the hide () and not the dispose (). That's because every time I call show (), imagine that leave the menu or I go to the start menu, the game, I come out ... every time I go back I will instantiate a new object of type Stage. If I simply do
Stage a Stage = new () and dispose () leave him dispose (), if I go four times on the screen, it will create four times one stage, but as I'm just creating the dispose () once because I just close the game once, there will be 3 stages that will be locked in memory, for example SpriteBatch It shall be locked in memory, and are not going to release it. And that would be a waste of resources. Then we badly despite what we have to do is
Stage rid of when we left the screen, for example to return to the Start menu. The other behavior we have to do is draw. In the stage now we add each of the actors who will participate in our game, for example add skewers, soil, minijoe ... each of these actors is defined by independent because it is the advantage of Scene2D, each actor is independent of the others, but somehow we
tell the Stage to coordinate this, and say 'Stage, calls on all actors to draw' or 'Stage, ask the actors to be updated.' For that, We have two important methods in Stage; One is draw, which we use to draw all players hit the stage, which is fine because we no longer have to do it ourselves; and the other is act, used to update the actors, so we think, for example, on skewers, who will be moving
to us on the screen. We must tell them to move periodically to go moving toward us. With the act (method) we can get it to do so. We say that in each iteration of the act () method to move a little to the left and by a call to act () deals with this. As is inconvenient we forget, I'll make the call to GL_CLEAR, and now that'll make the call to ClearColor, because I will come in handy
win a clear blue sky to make and not have to load the texture. First of all, we will test whether this actually works. I do not know why I test because obviously it not is going to work because I forgot one important thing, which is to present this screen in the create () method with a setScreen (new MainGameScreen (this)). I spent a esta because it is my MainGame. I mean, I who believe my screen. Now it should work.
What you saw before was a test that was done off camera before and had forgotten to put the clear, evidentemen It is clean blue screen because it is this. This stage is a little dead, missing things. Let's see how to create actors.
About the Author
Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.