Step 1 – Download libGDX
You can download libGDX using this link.
Here just click on the download button, and save the set up app on you desktop or somewhere else on you computer.
Step 2 – Install libGDX
The requerement of this tutorial is to have installed Android Studio, so you have to have installed Java as well. It mean you should just be able to open the downloaded file.
If you don’t have Java installed on you computer, then you can download it from here:
After you have opened the downloaded libGDX file, then you will get this.
Fill out the fields like you see it on the picture.
Destination: Where you would like to install the files.
Sub Projects: Select only Android
Extensions: Select only Box2d
We are going to use Kotlin, so check out the line of “Use Kotlin”.
Step 3 – Open in Android Studio
After a successful generation, we will open the project in Android Studio.
To do this, first open Android Studio. There click File menuoption on the top menu and select Open… then select the folder of the generated project. If it is done, then OK.
It will take few minutes, be patient. 😉
Step 4 – From Java to Kotlin
In build.gradle (Project: App) has to be this lines
- apply plugin: “kotlin-android”
- api “org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion”
Create Kotlin classes
To create the necessery Kotlin classes, open again the on the left side of the window the Project tab. Here open the needed folders.
- android – java – package – AndroidLauncher
- core – java – package – FlappyBird
Delete this two Java files and create new Kotlin files with the same names in the same folder.
Step 5 – First run
After the modifications the app still running, check it out and run it on an emulator or on your real device. If everything was successful, then you will see this … strange…. screen in landscape mode. 🙂
Compared to our previous tutorials it looks a little bit different. We have still the create method which runs when the app is run. Now we have a render method as well and it will contain our code because it runs again and again and again. So you can think of it as an ongoing loop and that is where we will put our code to animate our stripes to do our collision detection and everything like that to see where the game actually works.
We have some new classes here as well. SpriteBatches are the most important (arguably the only important) component of 2D drawing. A SpriteBatch contains methods for drawing groups of sprites onto the screen. And we have got textures which are basically images that we work with and think of them as sprites as well.
In the render method we have few lines, which sets the red background color, and draws to the screen the badLogic.jpg image to top the left bottom corner.
I hope the description was understandable and clear. But if you have still questions, then leave me comments below! 😉
Have a nice a day! 🙂