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:
- 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.
- In the Import Project dialog, select Create project from existing sources and click on Next.
- On the next page of the wizard, give your project a name on the Import Project dialog. Click on Next.
- If source files have been detected, make sure they are selected in the Import Project dialog. Click on Next.
- Make sure the gradle-wrapper library is found at this stage with the Import Project dialog. Click on Next.
- 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.
- Select the proper Java project SDK in the next Import Project dialog. Click on Next.
- 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:
- Select Run | Edit Configurations from the menu in IDEA.
- Click on the + icon in the upper-left corner and choose Application.
- You will be presented with the Run/Debug Configurations dialog.
- You should give your run target a name, such as
Run
. - You will need to update the Main class: setting with DesktopLauncher.
- 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)
- 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.
- 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):