Home

Awesome

Current version Downloads

This unofficial plugin adds a number of libGDX related features and tools to IntelliJ and Android Studio.

<!-- toc --> <!-- /toc -->

Installation

In IntelliJ or Android Studio go to Settings -> Plugins -> Browse repositories... and search for "libGDX".

Alternatively: download the zip from the Jetbrains Plugin Repository, go to Settings -> Plugins -> Install plugin from disk and select the zip you downloaded.

This plugin needs a recent version of the official Kotlin plugin (even if you only use Java), so please make sure to enable (and if necessary update) that plugin first. To update the Kotlin plugin to the newest version, go to: Tools -> Kotlin -> Configure Kotlin Plugin Updates -> Check for updates now.

Features

Inspections

libGDXPlugin adds several inspections, which look for possible issues in a project. Code inspections support both Java and Kotlin. To disable or enable inspections go to Settings -> Editor -> Inspections -> libGDX. See Inspections.md for an up to date list.

Color previews

When using a libGDX color in Java or Kotlin code (e.g. Color.BLUE or Color.valueOf("#0000ff")) a preview of the the color is shown in the left gutter. Color previews are also shown in the editor when editing Skin files and in the Debug Tool Window.

To disable color previews, go to Settings -> Editor -> libGDXPlugin.

Skin JSON support

Files with the extension .skin are treated as Skin JSON files. For files with the extension .json which look like Skin files, you are asked whether they should be treated as Skin files (this can be turned off in the settings). You can also mark and unmark files as Skin files using the context menu of a file.

<img align="right" src="/images/skinCompletion.gif" width="450">

For files which are marked as Skin files, the plugin provides additional Skin related support, including

[1]: Usages of the resource in Java/Kotlin code are not automatically renamed, expect when using the @GDXAssets annotation (see below)

JSON support

IntelliJ doesn't work well with libGDX-style JSON, which is more forgiving when it comes to things like unquoted strings and missing comma's. libGDXPlugin adds support for libGDX's custom JSON with the usual niceties of syntax coloring, completion, folding, etc.

To have libGDXPlugin treat a JSON file as a libGDX-style JSON file: in the Project Window, open the context menu for the file and select Mark as libGDX style JSON.

Atlas file support

<img align="right" src="/images/atlasFile.png" width="450">

Files with an .atlas or .pack extension are treated as Texture Atlas packfiles.

Atlas file support includes:

Bitmap Font file support

Files with a .fnt extension are treated as Bitmap Font Files, with:

Skin resources and Atlas region names in Java and Kotlin code

To get code completion, Go to Definition, Find Usages, Rename Refactoring, Diagnostics and Image previews for:

and related methods, use the @GDXAssets annotation to tell libGDXPlugin which files to use.

First add the annotation to your build. In build.gradle:


repositories {
    // ...
    maven { url 'https://jitpack.io' }
}

dependencies {
    // ...
    implementation 'com.github.blueboxware:libgdxplugin:1.23.1'
}

Then annotate Java fields and Kotlin properties where appropriate. Specify file names relative to the Project Root.

Java:

        @GDXAssets(skinFiles = {"android/assets/ui.skin"})
        // or Windows style: @GDXAssets(skinFiles = {"android\\assets\\ui.skin"})
        Skin uiSkin = new Skin(Gdx.files.internal("ui.skin"));

        @GDXAssets(
                skinFiles = {"assets/default.skin", "assets/main.skin"},
                atlasFiles = {"assets/images.atlas"}
        )
        Skin skin = new Skin();
        skin.load(DEFAULT_SKIN);
        skin.load(MAIN_SKIN);
        skin.addRegions(ATLAS);

        @GDXAssets(atlasFiles = {"assets/images/images.pack"})
        TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("images/images.pack"));

        @GDXAssets(propertiesFile = {"assets/18n/Messages.properties"}) // Specify the base file, including .properties extension
        I18NBundle bundle = I18NBundle.createBundle(Gdx.files.internal("i18n/Messages"));

Kotlin:

    @GDXAssets(skinFiles = ["android/assets/ui.skin"])
    // or Windows style: @GDXAssets(skinFiles = ["android\\assets\\ui.skin"])
    val uiSkin = Skin(Gdx.files.internal("ui.skin"))

    @GDXAssets(
            skinFiles = ["assets/default.skin", "assets/main.skin"],
            atlasFiles = ["assets/textures.atlas"]
    )
    val skin = Skin()
    skin.load(DEFAULT_SKIN)
    skin.load(MAIN_SKIN)
    skin.addRegions(ATLAS)

    @GDXAssets(atlasFiles = ["assets/images/images.pack"])
    val atlas: TextureAtlas = TextureAtlas(Gdx.files.internal("images/images.pack"))

NOTES

@GDXTag and short names in skins

Since version 1.9.9 libGDX skins support tagged classes: the ability to use short names for names of classes in Skin files. In addition to the standard, "built-in" short class names it is also possible to define custom short names for your own classes by overriding Skin.getJsonLoader() and calling Json.addClassTag().

libGDXPlugin understands the default short names. It also tries to determine any custom short names by looking for calls to addClassTag(), but there is only so much it can do.

To explicitly tell the plugin to recognize one (or more) short names for one of your own classes, you can use the @GDXTag annotation on that class.

package com.something.ui;

@GDXTag({"Widget"})
class MyCustomWidget {
  // ...
}

After this, the plugin will recognize Widget as a short name for com.something.ui.MyCustomWidget in Skin files. It is of course still up to you to make libGDX recognize this short name by subclassing Skin or by some other means.

Note that at the moment there is no way to tell the plugin a short name is only valid in specific Skin files, instead of all Skin files.