42 videos
238 minutes
And, however much we add actors, if our actor does not have any kind of behavior or is defined how any operation is drawn, we will not see anything on the screen. It is true that when you run the game and players have prepared and asked the draw scenario, what happens is that the scenario is drawn, but since nothing is drawn on the screen we see nothing. We are interested that the actor is drawn. And the first problem is:
I have to show an image on screen and must charge it at some point ... how the charge? first solution, which does not have to be the best. ActorJugador is always a class instance show (), ie, when we assume that libgdx is started. We could try to Texture create a field type within ActorJugador, and we will put in the constructor to load the texture. For example, player = new Texture ( 'minijoe.png').
With this we have my texture charged, and could say 'it works', for example batch.draw (player). Where did you drawing? Where it is placed. How sack coordinates? With getX (), brother setX () method, and getY (), brother setY () method. Apparently if I run this, yes it will show my texture player. But we have a problem: someone has forgotten define the dispose method, and now when I close this we have a MiniJoe
locked in the computer graphics card could not get out ... which is a problem because I do imagine that with a lot of textures and characters. The same is not the best way to download resources because we will leave the mobile video memory a little dirty. On the other hand this has another drawback. Imagine that gives me to change the name of the texture or introduce the second or third Minijoe. How do I tell the ActorJugador that must be drawn
with one or other texture? Or if I do the same with spikes and want to show several times the actor, pinchos, for each instance I have to instantiate a texture. If I charge 10 skewers, I have to load the texture 10 times, and that's still a waste. Then, as Actor class own addresses load resources is not right. An interesting pattern here is that instead of using the texture you're going to pass as a parameter. What you do here is simply that,
this.setJugador = player. And let me texture outside the passes in MainGameScreen, so that if you ever have to change textures or things, I have centralized it in the same code without having to go actor for reviewing each player, especially because you can let me uninitialized code and fail. I would load my texture, and would pass it as a parameter. I rename, but ... But this does not fix the problem at all because it is still necessary
call dispose. In this case what I'll do is, create a field, as usual, and finally the call texturaJugador.dispose hide (). In this case at least we are not polluting the video memory, though it may not be as optimal, because although we have a class BaseScreen call, an interface called Screen, Screen but already has a method called Dispose (), and we are constantly calling dispose () method.
We need a more efficient solution, and passes to use the dispose (method itself), for example calling texturaJugador.dispose () although this will introduce problems because as I said before every time you enter the screen a new texture now be charged. The old texture that is lost to assign the variable power is lost without disposear. In this case I realize that when I build the MainGameScreen class,
and I have the ability to create code here, in its constructor. Just as you can instantiate code in the builder player because libgdx It is already on and the texture is loaded at the time I charge the screen fades at the time that eliminated the screen. This is not the most optimal, but for now I'll tell you more about Scene2D and then you talk about a class called assetManager so that we do not also have our screens
full of builders of new textures but there may be a centralized class to deal with them. But for the moment with this we represent.
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.