"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Monday, 17 October 2016

LibGDX: The “Swiss Army Knife” of Java Games Programming

My few readers might remember I sometimes explore, and play with, game engines and libraries. I suppose it's a sort of “compensation” for my everyday work with not-so-exciting middle-ware and web-services projects. I already posted about Slick2D libraries for Java games but I was looking for something more complete and, most of all, that would allow me to develop also Android applications.
LibGDX is a Java game-engine that provide a vast variety of features for developing games. It's mostly aimed to 2D games development but it even provides some 3D features. In addition LibGDX can deploy games on different platforms like Java desktop or Applet, Android, HTML5 and IOS (with some extra requirement due to peculiar Apple developing policies). Last but not least a LibGDX project can include additional extension libraries helping to develop different aspects of game programming like AI, physics or networking (and this is the why of this post title).

First project creation

You don't have to download the whole LibGDX project in order to start to develop. LibGDX people suggest using the handy utility they provide, LibGDX Project Setup, in order to generate a skeleton project. The generated project will be based on the Gradle building tool that will think about downloading from the Internet all needed libraries and their dependencies.

In the project setup you're asked to define project and main class name, choosing the target platforms (I selected Desktop and Android ones) and selecting the optional extensions. The “Advanced” button provide some additional options like generating project files for a specific IDE (I selected Eclipse of course).
In addition of LibGDX provided extension libraries the tool also allow you to add to your project a bunch of third party extensions.
While the tool was busy creating my project I got the following message complaining about Android API being too recent then recommended.
I selected “yes” and continued without any problem (by the way project target and minimal version can easily changed afterward).

Importing and running first project

From Eclipse IDE I selected the “Existing Projects into Workspace” import wizard
I then selected the project folder, where the project setup tool had previously written its files, and did choose the three listed projects for import.
LibGDX setup tool created three projects: the “-core” one, in my case LibGdxDemo-core, contains the game logic. The other projects, in this case marked by the “-desktop” and “-android” suffixes, hold the platform specific code and configurations.

Running the projects

I had to fix some configuration detail, like setting the minimal required version appropriate for my old device, but at last I've been able to run my demo project on both platforms:

No comments :

Post a comment