The next step after making assets, such as making our texture atlas available to the game, is to load and use them. Loading an asset such as a texture can be as simple as the following line of code:
Texture texture = new Texture(Gdx.files.internal("texture.png"));
In the preceding example, we ask Libgdx to get an internal file handle to the texture.png
file. Invoking an internal file means that Libgdx has to resolve the file's path by scanning the assets
folder of the game. Then, the handle is passed over as an argument to the constructor of the Texture
class to instantiate a new object of this type. This texture instance can now be directly rendered to the screen with another line of code, as shown in the following listing:
batch.draw(texture, x, y);
Obviously, working with assets is basically very easy. However, this matter becomes a lot more complicated when we want to use several assets. It gets even worse if want to run the game on Android. As we have...