Native Multi-platform Game: Java to Kotlin (8 of …)

Ana Redmond
3 min readAug 17, 2018

--

With the proof-of-concept done, I am rapidly porting all the games. I built the games in Java on Android originally. Now I am converting them to Kotlin, so they can be run on both iOS and Android. Fortunately, IntelliJ automatically converts Java code to Kotlin. I just copy/paste the Java code into a Kotlin file, and it pops up a helpful dialog asking:

This looks like Java code. Would you like to convert it to Kotlin?

I answer: Yes!

Or, I move over entire packages, select all the files, right click and select

Convert Java File to Kotlin File

That’s all it takes. Then, I go through the code, and change the references to drawing and audio functions to the Game SDK. The first game took a bit longer. The Game SDK functions had to be adjusted to match what the games expected. Now, the process goes faster. After converting the kids math game, I run it on both Android and iOS to verify that it all works as expected. A more detailed testing cycle will happen later. Here is a video taken on an iPad running the picnic basket game

The easy bit is sometimes the hardest part. When it gets easy, there is no challenge, boredom can set in and I can lose focus. It is not as much fun as problem solving is. I have to keep reminding myself that Barb will be coming in once school starts, and I need to have this ready so she can test the lessons and the app on iOS.

Periodically, I run into interesting problems that need to be solved differently on both platforms:

  1. How to draw a dashed line: on Android, I used DashPathEffect, on iOS I used setLineDash function on UIBezierPath.
  2. How to draw a radial gradient: on Android, I used a RadialGradient shader on the Paint, on iOS, I used CGContextDrawRadialGradient function to do the same.
  3. How to set fade-in and fade-out the whole scene: I had done this previously by changing the alpha on the whole Canvas on Android. However, that was more computationally intensive and hard to replicate on iOS. So, instead, I covered it with a black rectangle that goes from opaque to transparent to fade-in and the reverse to fade-out.

Solving these problems keeps me going, and looking for the next problem to solve keeps me motivated.

Its almost end of summer. Kids were out of school during summer. I drove them to camp today and picked them up 3 hours later. It is a short amount of time for quietly coding. But, now that they are older, I can work after they get back home. Sometimes I need to take them for play dates, or swim class. I take my Kotlin-in-Action book with me to read while waiting at the swim class. Working on my own project gives me flexibility to manage my schedule. I don’t work on the code over the weekend. I dig in the backyard, go for a bike ride with Conor and the kids or just lie on the couch and read a book. Come Mondays, I am ready to take on the next challenge.

--

--

Ana Redmond

Software Designer and Developer. Mother. Building educational apps for my daughters to teach them math concepts at infinut.com