In this chapter, we will build the game Canyon Bunny, which was discussed earlier in Chapter 1, Introduction to LibGDX and Project Setup.
In this chapter, we will:
gdx-setup-ui
toolA Unified Modeling Language (UML) class diagram will give you the necessary overview of all the new classes that need to be implemented. UML will be explained later in this chapter. When looking from a software engineer's perspective, the architecture and the implementation code shown in this book does not always follow the best design decisions on purpose to keep the examples discussed simple and easy to understand wherever possible. Keep in mind that the primary objective of this book is to teach you how to work with and manage the vast complexity of creating games using LibGDX. The following parts are going to be very code-oriented, so be sure to make use of the class diagram as a point of orientation so that you don't get lost in all these code listings and their corresponding explanations.
By the end, you will have created and tested the base code that serves as the foundation for all the subsequent chapters in which more game features will be added successively.
Download and run the gdx-setup-ui
tool as you learned in Chapter 1, Introduction to LibGDX and Project Setup, and use the following settings:
CanyonBunny
com.packtpub.libgdx.canyonbunny
CanyonBunnyMain
C:libgdx
The following is a screenshot of the configuration described:
Next, click on Generate to generate all the projects. It will take some time to generate the projects. Now that all the projects are generated, you can now import these projects into your workspace.
Refer to the Creating a new application section in Chapter 1, Introduction to LibGDX and Project Setup, for more details.
Next, go to the Project Explorer window in Eclipse and open the strings.xml
file under CanyonBunny-android/res/values/strings.xml
. There is a name
variable that is used for the application name that users will see on their smartphones. The Project Explorer window can be opened by navigating to Window | Show View | Project Explorer.
Currently, the line of code should look like this:
<string name="app_name">My LibGDX Game</string>
Change the name to something more appropriate such as Canyon Bunny
:
<string name="app_name">Canyon Bunny</string>
Save and close the strings.xml
file. Also, in the Project Explorer window, remove the following two files and a directory that comes with the generated projects:
CanyonBunnyMain.java
file from the com.packtpub.libgdx.canyonbunny
package of the CanyonBunny-core
/CanyonBunny
projectassets
folder of the CanyonBunny-android
projectThen, open the starter class for the CanyonBunny-desktop
project and change the resolution parameters for width
and height
to 800
x 480
pixels respectively, as shown here:
cfg.width = 800; cfg.height = 480;
Save and close the file to continue. All done! You have finished the project setup for Canyon Bunny.
3.138.36.38