Some time ago, when I read that epic ported citadel demo on html5 , I decided to have an in depth look on how they did that and give it a try. The company I was working for, playerthree make also html5 web enabled games, so for me the possibility to write a game for the web and for native mobile device in c++ seems just a dream.
Epic were using emscripten, a cross compiler from c++ to javascript that promise that everything that can be compiled by CLANG, it can be ported in javascript. In fact the main principle behind this tool is that bitcode generate by llvm can be easily translate in some sort of assembler virtual machine running on javascript. In particular , it uses a javascript language subset known as asmjs. It sounds like this solution would bloat a lot of code by translate object files in some sort of ASCII version of compiled assembly code but turn out that since asmjs can be easily mapped to machine code, javascript engine can perform ahead of time compilation (AOT) and gain a massive performance gain. The asmjs guys declare that there is only a 2x performance slowdown when compared to native code on some javascript engine.
The whole toolbox you need for emscripten can be directly installed and configured using EMSDK . Once installed you only need to recompile your project using emcc command, the same way you'd compile your application with a normal compiler.
So, back to us I decided to write a small 2d engine to see if I was able to compile with emscripten, it support the following features:
- Sprite batching
- Texture atlas (Texture Packer and glideros format)
- Interpolators
- Timed callbacks
- font support (glideros format)
- touch input
- OpenGL 2.0
- basic memory management
- basic containers
- audio (only on windows at the moment)
On top of that I did a game, during a gamejam organized by playerthree to test if a full game could be done... and it worked. The web version even run on iOS8 and chrome mobile browsers!
in "the only way is up" you have to make your way from the bottom of the ocean to the surface. Simply move your mouse/finger to make the character strafe. You can play the web version here.
All the game design, graphics and audio were made by Gravy, playerthree creative director and co-founder.
All the game design, graphics and audio were made by Gravy, playerthree creative director and co-founder.
If you are interested, I've made the engine and the game code available on github. Apology for the game code since is something made during an 8 hour long jam, and if you have any question , feel free to ask.
No comments:
Post a Comment