Hacker News new | past | comments | ask | show | jobs | submit login
Making a cross-platform mobile game in Reason/OCaml (jaredforsyth.com)
170 points by jaredly on Jan 13, 2018 | hide | past | web | favorite | 24 comments

The game, Gravitron, looks very similar to an old Ludum Dare entry called Graviton:


(timelapse development video: https://www.youtube.com/watch?v=3tQ00R69rF8)

It's a really cool game concept, even cooler being written in OCaml! :)

Not only is this game a total blast to play, but it's also one of the only games that I think is best played on a trackpad instead of with a mouse.

However if I were the creator of this game, I'd be pretty pissed at the one in the OP. One was obviously inspired by the other.

Convergent evolution :) I made the version version of Gravitron in 2006

/u/jaredly, thanks for posting, this is really exciting! I've been reading about Reason here and there, and I've always wanted to write a simple game.

At the app/game level, is there any platform-specific code? Or is it all in src? And to clarify, the big news here is cutting down on the yak-shaving with the cross-compilers and build systems right? Does it enforce any conventions on the code? Did you use any frameworks to create the game itself?

I'll reply for Jared since he doesn't seem around. I work on Reason.

It's a single codebase and build system. There's platform-specific code buried in some conditional compilation in the Reprocessing drawing lib he uses: https://github.com/Schmavery/reprocessing

Here's a livestream of the Reprocessing folks making a flappy bird clone (https://github.com/schmavery/flappybird) from scratch: https://www.youtube.com/watch?v=5aD3aPvNpyQ&feature=youtu.be...

In the game, the only place I check the platform is to see how big I should make the screen (like 3 lines). Everything else is shared! The big news here is that you can use a single codebase (and a nice advanced language like ocaml), and deploy to 4 platforms. The framework I'm using is called "reprocessing", which is a ~port of the "processing" language to OCaml, targetting OpenGL. It abstracts out the different platforms.

I guess the Linux port wouldn't be a big thing, but what about Windows?

We are actively working on it. Linux's well on its way and is much easier than windows. We're open to PRs ;)

We consolidated web and native desktop in one repo https://github.com/bsansouci/reasongl. iOS and android are still out because we're still figuring how everything should fit together to be useful.

Very cool. Hot reloading in iOS would be extreamly useful. I remember that I used a plugin that was called injectionforxcode but it was not working very well.

I have yet to find a reason to support iOS hot reloading in this context to be perfectly honest. I use the desktop bytecode hot reloading (implemented inside Reprocessing so everyone can benefit from it), and it works wonderfully well. It's faster than anything you've seen before. And given that you probably want to be coding in Reason and not objc, it doesn't really matter what your render target is while you're iterating and being creative. I'm all ears if you can think of something though.

Flutter has a nice hot reloading feature: https://flutter.io/hot-reload/

Yeah, but then you have to use Dart.

That's actually a plus

Dart seemed pretty cool last time I checked it out.

There is no hot reloading in the toolchain, but the compiler is very fast. I am not sure what you mean by xcode plugin, this is a js application, Reason is syntax for ocaml using bucklescript backend.

This is both a native (as in binary) and js application. It compiles down to binary and uses OpenGL for native targets and WebGL for the web

Reason code can indeed be compiled to JavaScript using the Bucklescript backend (as can regular OCaml), but it can also be compiled to native since it's just a dialect of OCaml. In the latter case, the programmer would need to avoid JS interop or employ conditional compilation.

Can somebody compare Reason to Elm and PureScript?

Does it only work on desktop browsers?

By which I mean does the version that's compiled for browsers not work on mobile browsers? I noticed the Gravitron game loads on mobile but the layout is broken. Is that just a case of not being optimized to work for mobile browers? Or is there a limitation in the frameworks that prevents it from working in mobile browsers?

I'm not sure the answer, but since it's for sale on android and ios, I imagine there's not a lot of incentive for the author to make it work on mobile browsers if it's easily done.

I haven't optimized it for mobile browsers, but it wouldn't be hard. Was pretty heads down on getting mobile native out the door.

Great, thanks! This all came at a perfect time -- I was just about to start working on converting a bunch of our music education games to iOS. My plan was to do that, then convert our existing games from Flash to HTML5. If I can get this up and running, it would save a great deal of time.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact