Steps to create a well-behaved mobile game?

Hi all,

To help myself learn Defold I decided to make a simple mobile app. It pulls data from various web sources, parses and summarizes them, then uses GUI elements to display. It works very well.

I’m testing it on Android and have a couple minor oddities that I haven’t been able to find clear documentation on. Perhaps a few hints would get me on my way…

One, I’ve noticed my app on Android doesn’t want to be upgraded, I always have to uninstall and install new when I test each build. I’ve just been copying the .apk to my device and installing it.

Second I’m not sure how to make my app listen to the Android back button. It would be nice for it to detect that and exit cleanly or go to the background. Right now pressing back does nothing. To exit I switch out and then kill/close the app.

Is there a tutorial or documentation about making a well behaved mobile game with common functions like exiting cleanly?

Any hints are greatly appreciated. Thanks!

I don’t think this is Defolds fault but Androids, what is probably happening is that your device doesn’t know that new build is actually newer because the version number is the same. So the solution is to update your version number in your game.project file. Though because of the overhead I don’t think it is a very good one. Myself I have a python script that wraps bob and adb so that building, installing, uninstalling, starting, listening and all that on Android is only a few commands. It should be fairly easy to set up yourself, but I will see if I can release what I got somewhere.

You will need to map KEY_BACK in your input_bindings, people usually map it to be “back to the previous screen” and if you are on the main menu (or something equivalent for your app) you map it to exit the app. Here is how you exit a Defold app.

2 Likes

Thanks for the tips! I had browsed through the list of key commands but didn’t notice KEY_BACK until you said it was there.

Are you signing your APK by specifying a certificate and key or do you leave those fields blank? If you leave them blank we’ll generate a cert and key and that will differ for every build and it will not be possible to install a new version on top of an old one.

You should be able to set a keybinding for the back key and take appropriate action (os.exit() for instance)

Thanks for the certificate tip. The info in this thread ‘Use an unchanging default debug certificate when bundling for Android’ was also helpful.

just connect device to the computer and use ADB tool from Android SDK for easy change the app on your device.
it looks like: adb install -r myapp.apk