Update 15th October 2018: I found out today that this game is broken. In the browser, it does not run any more. A quick look with the browser debugging tools tells me there is some error when loading a font file, but I did not investigate more. This is a game I made 5 years ago, with a game engine that I used only once, back then, for this particular game. I really don’t feel like updating to the newest version and probably find out that the API has changed and I need to adapt this old code, so I have decided to leave it as it is right now. The source code is still available if anyone reading this is interested.
On the Berlin Mini Jam of August 2103 I took the opportunity to get a first impression of Cocos2d-x. It’s an open source, multiplatform c++ port of the Cocos2D game engine, which was written for iOS apps.
One of the themes was “The world ends in 2 minutes”. I took that literally and made a simple game where you get to choose how do you spend the last 2 minutes before the planet gets destroyed by an asteroid.
Being the first time I was using the library, my approach was to take the example HelloWorld app and hack it, looking up things in the online reference as I needed. I wasn’t left very happy with the online documentation though. In the official site, at least, it amounts to one simple tutorial and what looks like a dump of Doxygen generated documentation. I missed little snippets of code showing examples on how to use each class, like you have with Löve2D or Qt. On the other hand, the library itself seems to be quite well written, it was nice to use. Specially because using the C++ version meant that the IDE I was using (QtCreator in my case) would help me figure out things through the autocompletion feature. Speaking of which, Cocos2d-x comes with Qmake project files ready to use straight away, which was a very pleasant surprise.
Once the game was done, I decided that for such a small game I didn’t want to recompile for multiple platforms. People are more likely to try a game if it just runs in their browser rather than download an executable binary. So, I decided to give the emscripten port a try. Generating the webapp did work out of the box, without any need for tweaks. Unfortunately, it was quite buggy. There was a weird problem with the colors (everything appeared red), the way fonts were rendered, but worst of all, the performance was terrible.
Having it running properly, though, was not exactly a piece of cake. I encountered different problems on each browser that I tried. TrueType fonts were rendered in green (at least in Firefox), which meant that I had to replace all the labels and use a bitmap font (fortunately, I could find a freeware app online to convert ttf to bitmap fonts). Support for the WebAudio API is kind of broken on several browsers (Problems with Chrome and Safari), so I had to hack into the Cocos2d-html5 library and implement workarounds with the particular problems on each one of those browsers. And so is texture management with WebGL (Problems in Opera and Chromium). I spent almost as much time working around the different issues on each particular browser as I spent writing the app on the first place. My feeling after this work is of admiration for the developers of this game engine, because most of the stuff worked right away after all, with these few exceptions. They must have had to do tons of work to fix all the countless issues on the different browsers.
Here you can play the result of the port, online. The song is called “Duet Musette“, by Kevin MacLeod. You play the game by clicking on the options at the bottom right corner. The sound might still be broken depending on the browser you’re using, I am sorry about that.
- Link to the game (HTML5)
- Source code (the master branch is the html5 implementation, there is a cpp branch with the original implementation)