Loading and tracking assets

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 ...

Get Learning Libgdx Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.