The final goal of creating a battleship game was porting it to Android so I can run it on my phone. I was not in the mood to do all configuration and remember how to do it. This changed when GluonHQ introduced start.gluon.io.
In this brief post I will share my steps porting the Battleship Game to JavaFX.
Android application development
To take advantage of start.gluon.io I created a project and made it part of battleship maven project:
The I modified the original JavaFX app so I could use it in the Android ready app:
- Decoupled the application setup from a pure desktop app: Instead doing setup on desktop main, I moved it to a separated class, so I could reuse the setup in mobile app;
- Resize: Since I didn't know the target device size, I had to react to scene resize to redraw the game boards. This was easily accomplished by adding a default method in Screen interface, which is called when Scene is resized. Then screen can modify boards size accordingly.
Pros
- Speed: You can quickly develop, debug and test your application locally, don't have to wait a long time for compiling and things like that;
- Compatibility: Everything we do in JavaFX seems to work on Android. In battleship we have transitions, use of CSS and Canvas, everything seems to work in my mobile phone. It means that charts, binding, animation and other cool JavaFX APIs can be used for Mobile applications as well;
- Events: I used MouseEvent to retrieve where user clicks on boards, but in mobile phones we don't have mouse events, I didn't have to adapt mouse events, it just works!
- Modern: Use modern Java 11;
- Rich API: I noticed Gluon also provides great APIs to build apps, I didn't use it, but it is great to see that we could make use of some tested and mobile specific components.
Cons
- ComboBox and ChoiceBox does not seem to work. That's the only thing that really upset me, but I don't think that combox/choicebox are mobile friendly;
Final result
Conclusion
In this post I shared how I ported my JavaFX application to run on Android. That was a great experience, I really glad Gluon is working hard and I truly feel that Java WORA is true again. Thanks Johan, Jose Pereda and Gluon Engineering team for making it possible.
Source code: https://github.com/jesuino/battleship-game
Nenhum comentário:
Postar um comentário