Chapter 3. Configuring the Game

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:

  • Create the Canyon Bunny project using the gdx-setup-ui tool
  • Learn about the game's architecture
  • Test your basic code

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

Setting up the Canyon Bunny project

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:

  • Name: CanyonBunny
  • Package: com.packtpub.libgdx.canyonbunny
  • Game class: CanyonBunnyMain
  • Destination: C:libgdx
  • Generate the desktop project: Select the checkbox
  • Generate the html project: Select the checkbox
  • Generate the ios project: Select the checkbox

    Note

    Gradle users can also use the preceding configuration to generate the project.

The following is a screenshot of the configuration described:

Setting up the Canyon Bunny project

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.

Note

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:

  • Remove the CanyonBunnyMain.java file from the com.packtpub.libgdx.canyonbunny package of the CanyonBunny-core/CanyonBunny project
  • Remove all the images and folders inside the assets folder of the CanyonBunny-android project

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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.36.38