42 videos
238 minutes
To speak of regions, what I have done is put a second image called pinchos assets folder. These are the skewers with which we to stumble and that if we stumble, we die. As you can see is a curious image because the spikes have this point but I made the highest picture. Do not you cut it out better image? I mean, I think you see that there are many pixels that I do not use. This I have done for a reason,
and the size of the image is not accidental that is 128x128. In libgdx, as in other games that use OpenGL, textures are better loaded, if its size is a power of 2, for example 128, that is 2 ^ 7. In this case when you have loaded minijoe.png, I have not taken this into account and I consider that there is a penalty for using images that are not a power of 2, for example, 73 is not a number you can get if you raise 2
something, or 80. What you should do is treat OpenGL inside a specially made to look like it, but this takes a penalty. As pinchos.png occupies what must occupy 128x128 or 128x64 or 64x32 ... always a power of 2, it will load much faster and will be processed faster. But this is a problem, because my image has an area not use, because only interest me the pixels used by the image.
I ask libgdx that not only charge me the picture, but the cut. And for this type of earnings it is good to have the help of the regions. I tell libgdx, 'to see, fuck me this picture, and stay with this portion of here,' and that's what I'll do. Cargo my pinchos.png. Before I forget I make a dispose. And now I have to do is create my region to tell you where to cut. I do this by declaring an object of type
TextureRegion called regionPinchos, and I have it ready to build, as regionPinchos = new TextureRegion. I say what I want to use texture and what are its dimensions. I ask you to cut spikes at a particular point. (X, y) will I have to say where I want to cut, and (width, height) how high I want to be the image. Here are a problem because I have told you that the game has libgdx y = 0 below. But in the images,
the shaft and start up, that is, that if I cut an image, the (0,0) is up, and if we want to start cutting down we must have consider this. This is 0, that is 128, this is a scale. I have done accounts for you, and I have to cut back on y = 64. I'll ask you cut from (0.64), 0 because it is on the left and 64 because it is half. And that cut me something that measures 128 wide, which is the width,
and 64 because it is the other half of the imagen.Simplemente I tell you cut 0, 64, 128, 64. And with this and I have prepared. Now you will think that the need to disposear, but surprise, no dispose. Because after all the regions have no texture, are separate elements happened to him as a parameter, so it is understood that if I do a dispose () texture, the region stops working. Another warning,
not you to try to use an image that you have disposeado, because it can cause problems. Neither you nor heap up a region that has a disposeada image, because it can give a lot of problems. For example, now that I have this ready ... or actually going to remove it, because I will not abuse the SpriteBatch, but I will ask you to draw my region, regionPinchos. Android Studio marks these methods gray so you see that you can not use.
I ask you to draw on (250, 0). Here if you start counting down the y = 0 and go up. So we will see below right. Is almost as big as the character skewers, I will have a problem making the jump luego.Podéis do all kinds of tests: continue to say where you want to draw things. Do the test, draw a lot of pictures, make a loop so you can see
that is efficient display images if you use one SpriteBatch. In fact, I say that out of SpriteBatch is difficult to get the draw. Partly because you would have to use OpenGL as pure methods bind. It is difficult to work with OpenGL, partly why we want to use libgdx, It makes it very easy to work with images. There are more types of images, and when we start to see that there Sprites Scene2D. But it is a good start.
Let's focus on another important issue, which is the entrance.
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.