Programming Games for Android

Programming Games for Android 08: Size and position of images

42 videos

238 minutes

Now I can do, for example, it is that the image is drawn in the upper right corner of the screen. And as I already know how measured my big screen, I can do is to adjust the image to be drawn so that it fits exactly in the upper right corner. This requires not only enough to know how tall of the screen width and height, but I need to know how tall high and wide image,

to do a subtraction between what occupies the image which has the screen to be adjusted correctly. For example, If I calculate the width and height Joe Joe, I can make the image to be drawn in (width - widthJoe) and (height - heightJoe) to fit exactly on the top right of the screen. For these things I can ask my image measuring how wide, how tall high,

and this tells how many pixels occupies both horizontally and vertically. For example, the height and width of joe joe can ask him that. [Drums] This should be a whole in fact. Now I can show who does not want the thing (width - widthJoe) (height - heightJoe). And this is going to be displayed on the top right of the screen, as you see now. More or less because although not really looks great,

Here are a few hairs above, which are those with Joe. Let's make the hairs look better and so another method I teach OpenGL. When I clean the screen, cleaned of black. I can really ask you to clean my color you want. For this all that I have to do is another call to a method that is in Gdx.gl, which is glClearColor. GL has a lot of methods, all starting with gl because they are OpenGL

purely speaking, and it is true that there are many, I'm not going to get into all of them, but for example the color I care to tell me which color display a different color. The next time you clear call to display the color you asked. The parameters are red, green, blue and uses OpenGL RGBA alpha because as you can imagine. The parameters should be between 0 and 1, because it's like OpenGL works.

0 indicates no color, and 1 indicates maximum color. If you have used RGB know that is between 0 and 255. This is the same with 0-1 scale. I say 1 and it's all red. I say 0 and no green. Or I tell 0.5f and will be half blue, 128 or 127. And finally in alpha 1 because I say yes, I want it to look all powerful that can be displayed. And in this case will now display with a different color, and going to be able to see up here

so there are few hairs so this is part of the image and therefore shows a bit lower, but as you see here is my stooge showing in the upper right corner. Another interesting aspect of batch I can ask you to draw as many things as you want. I can make several calls to draw without any problems. I can ask him draw me one in 0.0, the bottom left of the screen.

I can ask him on the right side but down. You ask I can also draw horizontally me 0 but draw it all out possible and with this I would be asking me to draw 4 things. And it without any problem says 'hey, I figure you all' and is unfazed. But as I have said before there are many more methods in the SpriteBatch, for example, we can do we draw the image with a specific width and height,

for example 300x250. And in this case the image will look bigger undoubtedly because obviously in this case is being displayed in a larger space. An image is fairly intuitive and climbing. Just in this case it is shown blurred, yes. But he is much bigger. And like most great, as you can imagine you can draw itself looks smaller. Then, construct images is not very complicated,

then when we start with the game seriously and begin to carry things with Scene2D, we charge images to represent the state of play with images, as the puppet or the enemies we have to jump, or background. Always textures, which is the most basic way to draw things on the screen. But it is not the last, by the way, because we also, for example, TextureRegions, used to represent regions.

To find new courses, subscribe. There will be no spam, promised :)

About the Author

foto de jotajotavm
José Javier Villena

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.