This time we will take a look at the texture creation - the main graphic aspect of any game. The LibGDX engine we have chosen to work with uses OpenGL standard.
Let's start by opening "MyTestGame.java" file located in the "test-game" project. Let's clean this code up and we should get this result (or just simply replace your old code with this one):
Now if we start the game we will see a blank (or black screen). Your next step should involve creating a simple texture. You can do it in any graphic editor (eg. GIMP): create a square (64x64 pixels) divided in 4 squares (32x32 pixels each) and fill them with red, green, blue (RGB) and the remaining one leave as blank or fill it with white color and save it as "quads.png" inside the "assets/data" directory within your "test-game-android" project.
Then open "MyTestGame.java" file and use "create()" method in which you need to add this line of code:
In order to display this texture we will use SpriteBatch class, all you got to do is to add a line of code into the "create()" method we've used before. It shuld look like this:
Now call up the "render()" method and add this line of code:
If we decide to launch our project we will see the 4-color square displayed on a black background. We can manipulate the "render()" method as much as we need, for example we can add two more squares and make them bigger just by adding more "batch.draw" lines with different sizes of the same texture.
But what if we want to use only a part of the texture, then we will need the "TextureRegion" class applied in the "create()" method (in this example we choose to display only one of the 4 colors):
We also need to display it and we use "render()" method again:
Our next article will be devoted to the "SpriteBatch" class only and in more detail.
You can find Part 3 of this tutorial here.
What do you think about How to Make Android Games. Part 4.? Please, leave your comments in the section below.
Share this article with your friends:
No comments:
Post a Comment