Setting Up libGDX?

Ok, so following the posts on the discussion about why people are still using java2D I have decided I want to try out libGDX. I was linked to where to download a libGDX ui setup application and then a tutorial for libGDX.

The ui app has created four projects for me. I only want to program for desktop, what do I do now? I’m really confused. I don’t know what projects I need to work in or what other libraries I may/ may not need for libGDX.

Can someone help me please?

~Scyth

His might help you: Link

Just start coding in the libgdx project.
To start the project you coded, run the -desktop project. Everything is fine now.

I tried google and there was nothing that helped.

Matheus I have four projects:

game
game-android
game-desktop
game-html

in eclipse there’s errors beside the andriod and html one, probably because I do not have the libraries for those.

what one do I code in?

Write your game code in “game”, and start your game via “game-desktop”.

How was there nothing that helped in google? That’s how everyone else figured it out. I have to question your motivation if you have to ask just for the setup.

Thanks matheus :slight_smile:

@Jimmit, all that kept coming up was code.google.com or whatever

http://code.google.com/p/libgdx/wiki/ProjectSetupNew

theres a tool on this site that creates the projects for you if your having trouble

What’s wrong with code.google.com? You know it’s not all actual code, right? Some libgdx tutorials are on code.google.com, although some of them are outdated. The project setup remains the same tho.

If you have no desire to make the game work on Android or HTML5, you can simply delete those folders (or untick them while setting up the project in the project setup UI).

Yes, the android and HTML ones will give you errors and you won’t be able to compile them without the proper SDKs.

It doesn’t matter if you are just developing for desktop, though. Put your game code in “game” and to test it run the main class in “game-desktop”, like matheus said. Put your resources in assets/data of “game-android.”

Another way to set it up is to create a new class library in Eclipse, and point to LibGDX’s JARs and natives. Then you don’t need android/HTML projects, just one project for everything. This is standard practice for installing any 3rd party library in Java, and something you should get comfortable with if you plan to continue using Java. :slight_smile:

Is there anything we can do to make this easier? I’m a bit at a loss, feedback is appreciated.

If the setuptool allowed you to export a desktop-only project, I bet that would make things easier for beginners hoping to use LibGDX instead of Java2D/Slick2D. :slight_smile: Just my two cents…

Just letting you know I ATTEMPTED to use libgdx but I cannot due to a bug with it and mac OSX’s java 1.7 implementation - so if you plan on using it, you may want to stick with the older 1.6 release of java. I simply cannot use it as I rely on a number of 1.7 features. Oh well.

Why do you rely on 1.7 features? You realize that all Mac users < 10.7 (i.e. Snow Leopard and older) will not be able to play your game? Even if you’re just using Java2D.

The bug is not because of LibGDX but because of LWJGL (or, more specifically, some drastic changes that were introduced with Java 7). The LWJGL devs have mostly fixed it, although it still needs more testing.

This is one thing I’ll never understand about APIs. There’s 5 versions of something, and only the oldest versions are acceptable to use. Java 1.7 is great, has lots of new features and is a joy to work with. The reality is nothing supports it, so it’s effectively useless for anything. By the time 1.7 has any support I’m sure 1.8 will be out. I guess I’ll go back and switch out a lot of my clean exception handlers and switches back into noisy catch and if/else blocks…

If you’re relying that much on String switch and combined exception catches, I wonder whether you are doing something wrong… :wink:

I haven’t had a need for String switch since enums were introduced. Hopefully the introduction of String switch doesn’t encourage Java programmers to go back to using Strings as constants…

Ye of little faith…

It is incredibly useful for XML processing:

    private void processPropertyXML(final Element propertyElement) {
        final String propName = propertyElement.getAttribute("name");
        final String propValue = propertyElement.getAttribute("value");

        switch(propName) {
            case "DefaultStage": _defaultStage = propValue; break;
            case "PlayerStartX": _playerStartX = Integer.parseInt(propValue); break;
            case "PlayerStartY": _playerStartY = Integer.parseInt(propValue); break;
        }
    }

Of course when the input can be controlled enums provide the typical solution:

    private void handleStageMessages() throws Exception {
        Message m;
        if ((m = Messenger.getInstance().popMessage(MessageClass.Stage)) == null) {
            return;
        }

        do {
            switch (m.getMessageType()) {
                case CoinGenerated:         generateCoin((Coin)m.getData());                break;
                case CoinDestroyed:         destroyCoin((Coin)m.getData());                 break;
                case ProjectileGenerated:   generateProjectile((Projectile)m.getData());    break;
                case ProjectileDestroyed:   destroyProjectile((Projectile) m.getData());    break;
                case WarpActivated:         warpActivated((WarpZone)m.getData());           break;
                default:
                    throw new Exception("Unknown message type encountered in the messenger!");
            }
        } while ((m = Messenger.getInstance().popMessage(MessageClass.Stage)) != null);
    }

Now imagine that top block with a bunch of if() { } else if() { } else if ()s…

Agreed that XML parsing is much clearer with string switch. But is it worth losing potentially hundreds of users?

I used to write XML parsers like that; they got quite long-winded and difficult to scale and debug. Nowadays I lean towards JSON and other means of serialization.

class Level {
    public int playerX;
    public int playerY;
    public String someData;

    Level() { }
}

... load level from file ...

Level level = gson.fromJson(reader, Level.class);

But I guess that’s just preference. :slight_smile:

It IS sad. The only problem is linux and mac distribution - if it was available by default, it wouldn’t be a problem.
Not that I use 7 features…

Well we can hope: “I anticipate rapid adoption of Java 8 (much faster than 7)”