Discussion in 'The Common Room' started by Bemoliph, Aug 21, 2015.

  1. Bemoliph

    Bemoliph High Priest Staff Member

    Likes Received:
    LibGDX is a cross-platform game framework written in Java. You can deploy the same(ish) code and assets to the desktop (Windows, Mac OS X, Linux), mobile (Android, iOS), and generally any WebGL-enabled browser. It also supports a bunch of popular third party libraries like Box2D to make your life easier.

    There's an official wiki with installation instructions for various IDEs. Unfortunately, it's not well organized and somewhat vague at times, so I've cobbled together my own Getting Started Guide using NetBeans. I assume you're starting clean, so feel free to skip stuff you already have.

    1. Download ALL the things!
      Just install these in the order they're listed and it should be fine.

      For the basics (desktop + browser),
      • JDK 7 or newer. Includes the matching JRE.
      • Netbeans 7.3 or newer. The Java SE (smallest), Java EE, and All editions work.
      • Gradle Support plugin for NetBeans. Search for it in NetBeans at Tools > Plugins > Available Plugins.
      • LibGDX Project Generator. Not an installer, just something you run. Additional auto-download inside on first project generation.
      • OPTIONAL: Mercurial (Hg) or Git for source control. NetBeans automatically supports either. For team projects, also adding BitBucket (Git + Hg, free private repos) or GitHub (Git only, large files support but paid private repos) is helpful.

      If you also want Android support,
      • Android SDK (tools only)
        • In an elevated command prompt (press start > type cmd > ctrl + shift + enter), set the ANDROID_HOME variable to the SDK's install location with SETX /M ANDROID_HOME "C:\Program Files (x86)\Android\android-sdk" (but adjusted to your installation).
        • Additional downloads inside the SDK Manager. At minimum, get the latest SDK Tools and SDK Platform-Tools, then the correct version of SDK Build-Tools, SDK Platform, Sources for Android SDK, and possibly a System Image for emulation (see AVD Manager and docs).
      • NBAndroid plugins for NetBeans. Add the link as an Update Center in NetBeans at Tools > Plugins > Settings > Add, then install Android and Android Gradle Support from the Available Plugins tab.

      If you also want iOS support,
      • Sorry, I have no idea since I don't have a Mac to test with.

    2. Project Setup

      Run the LibGDX Project Generator (gdx-setup.jar) and give it a Project Name, Package Name, and Game Class Name. Set the Destination to where the project files should exist - it DOES NOT append your Project Name as a new folder!

      Pick the platforms you want to release on AND have installed support for. They're all checked by default, so turn off what you don't need.
      • Desktop: Windows, Mac OS X, Linux
      • Android: Android devices, like phones and tablets.
      • iOS: Mobile Apple devices, like iPhones and iPads.
      • HTML: Web-GL enabled browsers. Achieved by conversion to HTML+CSS+JS via GWT.

      Pick the built-in extensions you need for your project. The tooltips are vague, so here are some similarly vague descriptions WITH LINKS:
      Click Generate when you're ready, let it download the extra stuff it needs, and then you're almost ready!

    3. Extra Configuration
      There are a few small things to fix:
      • Javadocs: LibGDX projects don't include the official Javadocs by default, so we have to add the sources JAR via the Gradle dependency manager by editing build.gradle in the project's base folder:

        Using a text editor, find the project(":core") section of build.gradle and add the sources line like so:
        project(":core") {
                    apply plugin: "java"
                    dependencies {
                        compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
      • .hgignore: For Mercurial users, add this .hgignore to the project's base folder. This version preserves the build.gradle files.

    4. Using NetBeans + LibGDX
      LibGDX projects consist of a main project containing several sub-projects, including core (common code for all platforms; game logic) and one for each platform (desktop, android, etc; specific code that runs the game). Use File > Open Project... to select the main project wherever you generated it, then expand the sub-projects in NetBeans and double click each one to open them.

      You'll work mostly in core, but you need to run the correct platform-specific launcher to play your game. Since NetBeans subtly switches sub-projects depending on what you last (de)selected, set desktop (or whichever platform) as the "main project" to make the green Run button always launch the right thing.


      If you can run it and get this ugly thing, you're ready to make games!

      A small aside: Source control in NetBeans has a similar issue with the multi-project where the Team menu will operate on the current sub-project only, possibly missing changes elsewhere. I'm not sure how to set a "main project" for repository purposes, so I've just been specifically using Right Click > Mercurial/Git/Whatever on the [root] project in the Project Viewer to be sure. I also recommend setting up the stuff in Team > Properties after making the repository if it's not done in a config file elsewhere.

    5. Do the Tutorial!
      Now that you're all set up, it's finally time to do stuff! ...except we weren't magically born knowing how LibGDX works, it's probably best to do some tutorials first:
      • A Simple Game: An introductory tutorial from the official wiki on catching the rain with a bucket. Try drawing your own art instead of using theirs!
      • Extending the Simple Game: Part two of the official wiki tutorial. Adds a main menu to the game.
      • Zombie Bird: A bottom-up tutorial on using LibGDX to raise Flappy Bird from the dead. Good emphasis on code structure and concise plain language explanations.

      I'll add more specific links as I try them myself or get recommendations, but you can sort through some yourself at the wiki.
    Last edited: Sep 1, 2015
    Elf likes this.
  2. Bemoliph

    Bemoliph High Priest Staff Member

    Likes Received:
    I've updated the original post with a Getting Started Guide for NetBeans users. The official instructions are workable, but they're kind of a mess and my version has some added workarounds for things I bumped into.
    Elf likes this.