Book Image

Mastering LibGDX Game Development

By : Patrick Hoey
Book Image

Mastering LibGDX Game Development

By: Patrick Hoey

Overview of this book

Table of Contents (18 chapters)
Mastering LibGDX Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Running the default demo project


Now that we have an overview of the project structure, we can now run the project sample to make sure that your project is configured correctly, is building, and can run.

You can either double-click on the BludBourne.ipr file in the project root directory or launch your IDE and import the BludBourne project. In order to import with IDEA, execute the following steps:

  1. Choose File | New | Project From Existing Sources. Choose the root directory of your project in the Select File or Directory to Import dialog. Click on OK.

  2. In the Import Project dialog, select Create project from existing sources and click on Next.

  3. On the next page of the wizard, give your project a name on the Import Project dialog. Click on Next.

  4. If source files have been detected, make sure they are selected in the Import Project dialog. Click on Next.

  5. Make sure the gradle-wrapper library is found at this stage with the Import Project dialog. Click on Next.

  6. Make sure the module structure includes both the core and desktop modules in the Import Project dialog. Click on Next. You may get a popup dialog asking whether to overwrite or reuse the files. I would recommend the reuse option.

  7. Select the proper Java project SDK in the next Import Project dialog. Click on Next.

  8. On the last page of the wizard, click on Finish.

If you are running IDEA, and you committed the initial project to Git, you may see the following Gradle-based balloon notification when you start the IDE for the first time:

Unregistered VCS root detected 
The directory C:\BludBourne is under Git, but is not registered in the Settings.

In order to resolve this, with the project open, go to File | Settings. Under the Settings dialog, select Version Control. Your project should be listed under Directory on the right panel, under Unregistered roots. Select your directory and click on the + button on the right. Select Apply and OK when finished.

If you are running IDEA, you may also see a Gradle-based balloon notification when you start the IDE for the first time:

Unlinked Gradle project?
       Import Gradle project, this will also enable Gradle Tool Window.
       Don't want to see the message for the project again: press here.

Click on the Import Gradle project link (in the balloon notification at the bottom). In the Import Project from Gradle dialog, make sure that your root project build.gradle is configured in the Gradle Project path. Also, make sure the Use default gradle wrapper (recommended) option is enabled. Change the Project format: option to .ipr (file based). Click on OK when finished.

If you are running IDEA, you may also come across this Gradle-based notification when starting the IDE with a clone of the BludBourne project repository:

Error:Unable to make the module: <module>, related gradle configuration was not found. 
Please, re-import the Gradle project and try again.

In order to resolve this issue, go to View | Tool Windows | Gradle. Click on the refresh button in order to synchronize all linked projects.

In IDEA, select Build | Make Project. You should now have successfully built the startup project. We will now need to create a run target:

  1. Select Run | Edit Configurations from the menu in IDEA.

  2. Click on the + icon in the upper-left corner and choose Application.

  3. You will be presented with the Run/Debug Configurations dialog.

  4. You should give your run target a name, such as Run.

  5. You will need to update the Main class: setting with DesktopLauncher.

  6. You will also need to set the Working directory: path to <project root>\core\assets. If you don't set this, you will get the following runtime error:

    Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: badlogic.jpg
       at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
       at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
  7. You will need to set the Use classpath of module option to Desktop since this is where the main entry point of your game lives.

  8. Click on OK when finished.

Now, everything should be configured to finally run. From the menu, select Run | Run target. If all the dependencies are correct, with a proper Gradle build setup and project configuration, you should see the following screen (Figure 10):

Figure 10