Loading and tracking assets
After making our assets, the next step is to allow our game to use them and load the texture atlas. 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 we want to run the game on Android. As we have...