Today I want to add initial support for Android and iOS devices. I want to handle hardware back button on Android, and handle onResume
/ onPause
events both on Android and iOS (I’m not an iOS developer, so I guess it will be viewWillAppear
/ viewWillDisappear
or applicationWillEnterForeground
/ applicationDidEnterBackground
or something like that).
Initially I think that onPause
/ onResume
will be the hardest part, but hopefuly luxe is based on show, which is based on SDL2 itself, and it handle these events for me.
To use them in luxe you should override onwindowminimized
and onwindowrestored
methods. That all 🙂
Back button
Handling back button is also simple, but requires a bit of magic. You can handle it using onkeydown
or onkeyup
, but there is one problem – nor luxe nor snow doesn’t have built-in keycode for back button on Android. To find out this code I add logging to onkeyup
. Here it is – 1073742094
.
While testing how transitions between screens work, I notice that rarely I can’t quit from the game (usually when you press back button on menu screen, it call Luxe.shutdown()
and the application must terminate itself).
Fixing shutdown
I look in my code, in luxe code, in show code and even in SDL2 (just a little), and didn’t find anything suspicious. I did not want to spend much time on this, so I create special quit screen, which is just black screen.
Instead of calling Luxe.shutdown()
in the menu screen, I change screen to the quit screen, and inside quit screen call Luxe.shutdown()
after a small timeout (enough to wait for a menu screen fade out).
In worst case (when shutdown fails) user will just see black screen. It is not OK, but it’s better than if the game continued.
See you later!