Game Development Reference
In-Depth Information
The added code provides a convenient way to rebuild the texture atlas every time the
game is run on the desktop. The rebuildAtlas variable controls whether the atlas
is rebuilt on startup or not by setting it to true or false . Using the TexturePacker
class to create the texture atlas is pretty straightforward. It contains a static method
called process() that takes an optional settings object to configure the way the
texture atlas will be generated as well as the three parameters that are mandatory.
The first mandatory parameter is the source folder that contains our image files.
The second one is the destination folder where the generated texture atlas should be
created. Finally, the third parameter is the name of the description file that is needed
to load and use the texture atlas.
The source folder (in our example, assets-raw/images ) is specified relative to the
desktop project as the TexturePacker code is executed from here. The destination
folder (in our example, ../CanyonBunny-android/assets/images ) is also specified
relative to the desktop project. However, the resulting texture atlas has to be put
into the assets folder of the Android project so that it becomes available to all
platform-specific projects. The description file (in our example, canyonbunny.pack )
will be created by TexturePacker and will contain all the information about all the
subimages, such as their location in the texture atlas, their size, and offsets.
However, for projects generated from Gradle, the project folders will have different
names, refer to the gdx-setup versus gdx-setup-ui section in Chapter 1 , Introduction
to LibGDX and Project Setup . Hence, for targeting the assets folder inside the
Android project folder in a Gradle-based project, the destination path is ../
android/assets/images .
The maxWidth and maxHeight variables of the Settings instance define the
maximum dimensions (in pixels) for the texture atlas. Always make sure that a
single subimage does not exceed the maximum size of the atlas either in the width
or height or both dimensions. Padding the subimages in the atlas will reduce the
available size a little bit more, so make sure to take this factor into account too. The
debug variable controls whether the debug lines should be added to the atlas or not.
We use the drawDebugOutline variable to set the value to debug. The static variables
rebuildAtlas and drawDebugOutline are there just for our convenience to make
these two behavior controls stand out a bit more because we usually change these
variables every now and then while debugging our game.
 
Search WWH ::




Custom Search