Hello there, the future indie game developer, so you have decided to begin game development in with libgdx! Alright. So, in this libgdx tutorial, we will learn to setup our computer for Game development in LibGdx.
For creating games in LibGdx you have to write your code in JAVA or Kotlin and then you have to compile them (converting your code into Bytecode) and pack the codes and libraries for running your program on particular JAVA Virtual Machine (JVM) which is basically your smartphone and your PC.
So for doing all this compiling and running stuff, we will use the Android Studio but using android studio is not compulsory you can also use Eclipse and IntelliJ IDEA or even Command Line gradle for compiling and running your Game.
So Now let’s discuss Android Studio in brief.
What is Android Studio and Why we use Android Studio?
Android Studio is an IDE which stands for Integrated Development Environment. It is a software application that provides various facilities to programmers and developers for their software development.
An IDE consists of an intelligent source code editor which helps you to write your code faster, better and errorless. It also has building tool with debuggers that help you to run your code on any platform and debug it easily and it will have so many other facilities like import and exporting your code and etc.
It has its own specification requirement for working so you can match your pc specification at click here.
Why we use Android Studio? Well as explained above, as an IDE, it is a smart, better and faster way, as well as libgdx allows direct usage and production of games through the android studio, we also have a big community online to help us. So, we should use it.
Another question is that comes to mind is as follows.
What if we want to create games for other platforms also like desktop or ios and not only android?
Well, that’s not a problem because we are using LibGdx which is a platform-independent development framework. It consists of several libraries for platform independence so you can write code once and it will work on every platform of this world.
One more thing, Android Studio is not for creating an app on Android only it can also be used for deploying your projects for every platform. It will help you to run your code on desktop and ios or on other platforms too. So, your game will work everywhere.
Now let’s start!
Step 1 - IDE and download libGDX
You can begin by Downloading Android Studio. This tutorial is about libgdx so we won’t get more into the ide stuff.
After downloading and installing android studio or any other IDE of your wish. Download the libGdx jar package.
After downloading the libGdx jar file, just open it.
If you are not able to open the file then install JDK and setup your environment variable for JAVA. Learn more about installing java on your system
After opening libGdx, you will get this user interface as shown below:
Step 2 - Set up a game project
This is a user interface to create a project for libGdx. First, you have to write the name and the package name of your project and then the name of the main game class.
Then you have to give the location of your project where the created project will be stored then you have to give your SDK path where SDK is installed.
if you don’t know the path then go to the android studio > configure > SDK manager and just copy paste the Android SDK location here or you can set SDK environment variable.
Then you just have to select your games platform for working and select his extra extensions if you want to add in your project what is the use of these extensions is we further discuss.
After deciding your configuration (do as shown in the next pic for simplicity), just click on Generate and accept all alerts.
Your project will start setting itself but it will download its libraries and some more packages so it will take a few minutes to set up.
if you get something this:
Then Congrats your first game project is now created!
Open android studio and import your project to it and wait for a few minutes so the android studio will create your Gradle project.
After the import process finishes the Gradle build, you have to open the main class inside your core folder of your project tab like this:
If you get an error like this “configuration on demand is not Supported” then:
- goto files > settings > build, execution, deployment > compiler
- uncheck configure on demand
- apply the changes and press ok
Now go to “build and make your project”. Or else you can press
ctrl + f9 shortcut key and wait for Gradle build.
In this core file, you can write the whole game and you can see the code which is default given by the libgdx.
Step 3 - Running our game on desktop
Now we have to run and test the code on the desktop. Just click on the run (toolbar, a play icon) and then click on edit configuration after that you have to add a new configuration so that click on + (plus) icon then you will get this.
Click on the application and then fill the application like this:
then apply and click OK. Finally click again on run to get your final result. It will take time for the first run due to compilation and output will be as shown below.
if you got an error and don’t get this window then don’t be panic. Sometimes this will happen due to the syncing of different files. So just try to run again. If you still have any issue, comment below. I will answer back!
This is the result of the default libgdx sample application, where the image you are seeing is the logo of badlogic games. Now you have learned how to run begin writing libgdx code and how to create a libgdx project.
Thanks for reading up to here. This was all about the first step in LibGdx game development. If you have any questions then comment below and don’t forget to give your reactions stay tuned for the next tutorial in the series!