Working from sources

Libgdx is truly awesome and it will probably suit your needs perfectly. However, some people might need extra behavior or a slightly different API.

The first thing you should try is to add the desired functionality on top of an official stable Libgdx release. Were that to prove impossible, you would have to modify Libgdx itself to make it behave the way you want.

Throughout this recipe, you will learn how to grab Libgdx's repository, make changes to it, and use it for your game.

Getting ready

You will need a Git client to clone the Libgdx repository. We discussed that topic in the Using source control on a Libgdx project with Git recipe of Chapter 1, Diving into Libgdx.

Libgdx uses Apache Ant, which is an open source Java-based build system, very much like Gradle. You can grab the latest binary distribution from http://ant.apache.org/bindownload.cgi.

Download the latest one, unzip it in the folder of your choice, and add the bin subfolder to your PATH environment variable.

The Libgdx project itself still uses Eclipse projects; it is recommended you have that IDE installed on your machine. Refer to the Setting up a cross-platform development environment recipe in Chapter 1, Diving into Libgdx, for more details.

How to do it…

Everything should be ready now. Follow these steps in order to work from Libgdx sources:

  1. Clone the Libgdx repository using [email protected]:libgdx/libgdx.git. You can either use SourceTree, the Git client of your choice, or plain old Git.
  2. Open a command-line window in the Libgdx folder.
  3. Libgdx depends on a few binaries that are not in the GitHub repository for space reasons. However, you can easily retrieve those dependencies with Apache Ant as follows:
    ant -f fetch.xml
    
  4. Now you can build Libgdx using Ant:
    ant
    
  5. Once the process has finished, proceed to import the projects in an Eclipse workspace. Right-click on the Package Explorer window, select Import | General | Existing Projects into Workspace. Hit Next and click on Browse to find the clone directory. Check all the projects and select Finish.
  6. Now you are free to make any changes you want to the code.
  7. In order to use your changes, you will have to make your projects depend on the Libgdx sources as described in the following list. Note that this cannot be used in combination with the Gradle setup as explained in Chapter 1, Diving into Libgdx.
    • The core project has to depend on gdx
    • The desktop project has to include gdx-backend-lwjgl
    • The Android project will have to use gdx and gdx-backend-android
    • The HTML project has to depend on gdx-backend-gwt
    • The iOS project will have to use gdx-backend-robovm

How it works…

By making your game depend on Libgdx sources, you can make changes to the core and see them reflected on the game right away. Additionally, you can still keep pulling changes from the main repository to stay up to date. Naturally, this has the downsides of requiring you to be extra careful and a bit more cumbersome.

See also

  • The Using source control on a Libgdx project with Git recipe of Chapter 1, Diving into Libgdx
..................Content has been hidden....................

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