Switching from LibGDX to KorGE - with Kotlin

Anything libgdx related goes here!

Switching from LibGDX to KorGE - with Kotlin

Postby Tobse » Tue Mar 12, 2019 10:54 pm

Hi, my name is Tobse and I started writing my first LWJGL based games in 2007. There I used Slick 2D before I switched to libGDX. Then three years ago I switched all my private programming projects from Java to Kotlin. Except for the web build, this also worked well with libGDX. And I also tried out the great KTX libs which helps a lot to write seamlessly in Kotlin style. But after a few Kotlin - libGDX projects I thought that things could be much better with a new approach. Why not use Kotlins multiplatform feature to get a real platform independent game library. Written from the ground up to use Kotlin paradigms, like builder patterns, coroutines, inline classes, default parameters, operator overloads and many more. And then I found the KorGE by Carlos. A free and OpenSource Kotlin framework, which seems to be a perfect match.

KorGE is a pure Kotlin game framework.

It supports these backends, which can all be built by a single Gradle command:
  • JVM build -which runs on Win, Linux, Mac
  • Native builds for Win, Linux - which are small and run without a JDK!
  • Android apk
  • Native iOS - without any RoboVM ore sth. else
  • Web build - which runs in the browser
  • Cordova builds - which packages a webapp and can run on nearly every platform.


Compared to LibGDX it also supports
  • Images, Textures, Filters, 2D, 3D
  • Sounds (wav, mp3, ogg)
  • Particels, Bitmap Fonts, TileMaps
  • GamePad, Touch Controller, KeyBoard
  • Physics (Box2D) and Animation library
  • 2D Scene API & 2D UI library (KoreUI)
  • Geometry, Shape, Math (KorMA)
  • Skeletal Animation (Dragonbones)

In addition there is also more:
  • Async dependency injection (Korinject)
  • Lip synchronization (LipSync)
  • SWF support
  • Native Builds
  • Built in testing support

I ported my HitKlack game from LibGDX to KorGE and want to share my experience.

The Game
In short: It's a retro console game remake of the HitKlack. A handheld console of the 90s.


You can find the LibGDX HitKlack game here: On Github or On the forum.
The ported version is also available On Github or on the website.
There you can also test the instant play web app.

Migration Steps
You can also follow my steps in the git log.
I started with the korge-hello-world-template and simply copied all Kotlin files and resources to the template. The only Java file was `SmartphoneLauncherSD.java` which was't necessary anymore. But thanks to IntelliJ and its Code/Convert Java File to Kotlin file it would be also easy to convert Java files to Kotlin.
Then the first thing I wanted to achieve was a clean compile, not a working game. So I removed all imports com.badlogic. which were not present anymore. And I removed the import java.util.* imports, because I wanted to switch to a 100% Kotlin version which doesn't rely on the JDK. Some of the libdx classes were very easy to replace. For example the com.badlogic.gdx.graphics.Color which could be replaced by fields out of com.soywiz.korim.color.Colors The new type is com.soywiz.korim.color.RGBA.
The only java util access was java.util.Random which was very easy to replace by kotlin.random.Random.
For the other few missing classes I created a libgx.emu package where I simply copied missing classes. For example a copy of the ApplicationListener.
So it wasn't hard to get a compiling copy of my game.

The next step was to add images and sounds. Loading resources is also easy:
Code: Select all

But the pitfall is, that readBitmap() is a suspend function. This means that this is async and we have to call it inside another suspend function.
This way we can also load sounds:
Code: Select all

Wav is supported by default. To enable mp3 and ogg sound file support on all platforms we have to add an additional dependency to the build.gradle.kts:
Code: Select all
korge {

The only missing thing was a game loop to let things roll. A naive way is to add a timer of seconds on your own and create your own game loop:

Code: Select all
private var time: Double
private fun getDeltaTime(): Double {
    val deltaTime = PerformanceCounter.microseconds - time
    time = PerformanceCounter.microseconds
    return deltaTime / (1000 * 1000)

A better and simpler approach is to use the com.soywiz.korge.component.UpdateComponent which has:
Code: Select all
interface UpdateComponent : Component {
   fun update(ms: Double)

Simply extend the UpdateComponent and add your game or component to the KorGE view:
Code: Select all
com.soywiz.korge.view.View.addComponent(c: Component)

So we can finally start the main.kts by running the Gradle task: runJVM.

Porting a LibGDX game to KorGE is easy and straightforward, especially if all files are already written in Kotlin. From a OOP view, beginning from the first lines, it feels like doing it in the right way. Instead of accessing almost everything in a static way, KorGE provides useful, well-structured builders, async loading methods, meaningful default parameters and clever extension methods to build your game. Nearly everything I used in my games like Sounds, Images, SpriteSheets, GamePad and so on was available and worked in the same way. The only thing which I didn't get was vibration support ;-)

To package the game for another platform couldn't be easier. Just call one Gradle command and the magic happens: you get a native Windows exe with an icon which can run without any Java installed. That's really a cool moment for a Java dev.

What do you think of Kotlin game dev in general?
Is multi platform an important feature for you?
Would you also consider switching to KorGE?

I'm very curious for any feedback.

Best wishes,
Posts: 13
Joined: Sat Feb 05, 2011 9:59 am
Location: Germany

Re: Switching from LibGDX to KorGE - with Kotlin

Postby david_dev » Fri Mar 15, 2019 10:18 am

Hi Tobse,

I read all your post and the links you wrote... For my point of view seems a very interesting alternative to the java+libgdx+robovm.

I've been using libGDX for 3 years and I'm really very happy, and have enjoyed a lot developing with this incredible library/framework. Recently I ported some of my games to iOS (with Robovm) and that was a real nightmare. But it worked! ... Without too much work. I have to say that I didn't had any previous experience with Apple.

Now the questions about KorGE.
- Your sample game (HitKlack) was created for desktop, web, and apk, what about iOS? What are the pitfalls there? Is real native in iOS or uses some kind of virtual machine?
- I haven't seen anything about localization. Uses the same i18n system as in libGDX?
- I use a lot libGDX's Scene2D. Will I be able to "port" my code (Kotlin code) to the KorGE library.
- What about the platform specific code : Ads (Admob, FAN, UnityAds, mediations,...) , in-app purchases, licensing, Google Game Services (or Apple Game Center), Firebase ?
- Do you think KorGE is currently enough mature (seems to be maintained only by Carlos) to start a long-term project?

Thank you for the insights!
Posts: 11
Joined: Fri Mar 04, 2016 5:47 pm

Re: Switching from LibGDX to KorGE - with Kotlin

Postby chavalot » Sun Mar 17, 2019 11:26 am

I've been watching Korge and he looks good but he still needs to work on something serious with him.
There is a lack of documentation on how to start a project from scratch and that will take some time to see if it is stable or not.

It would be interesting if libgdx was integrating more functionalities as other frameworks do.
It would still be the best for java videogames and if the future has to be kotlin then we will have to switch to kotlin.
Posts: 9
Joined: Thu May 22, 2014 10:45 am

Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest