2 years of indie gamedev

It has been slightly over 2 years since I started my indie gamedev journey. I began my life overconfident, despite reading the warnings of many who have failed or suffered along their own paths toward independent game development.

coding_is_hard_confidence_competenceI will spare you the bush-beating of how hard I fell from my initial period of extremely bloated self confidence, into the pits of despair & loneliness. However, as a personal milestone, look! I’ve survived for two years as an indie gamedev. Things can’t possibly get any worse. Even if I’m way past my age to be a newbie in this industry, I can keep going, heck, maybe catch up one day. Maybe. I won’t know until I get there.

To all the struggling gamedevs like myself: Hang in there! We’re all in this together.

 

Writing libraries for Haxe

I rarely write to this blog anymore, but I don’t want to desert it. So I figured to at least update once a month on things that I picked up, even if they’re totally random.

Writing libraries for Haxe is actually pretty easy, but I totally avoided that at first because I thought it was some advanced wizardry. There are three ways to write libraries (or plugins, whichever is the correct term):

  1. Using extern
  2. Injecting code
  3. Magic code

1) Externs

Extern is written something like this (from my github page):

When you prepend extern to a class, it means that the class should exist outside of your haxe code. In my case above, my class WynGA  does not actually exist — it points to an object wyn_ga I have written externally (or to be precise, it’s accessed via window.wyn_ga ) and manually embedded in my index.html. The wyn_ga object contains all the functions written above.

The reason (I think) you would want to use extern is when you have a lot of platform-specific code and can’t be bothered to write them in Haxe language. Or if you have code that doesn’t belong to you, e.g. JQuery, and you just want to point directly to the file (e.g. you have a  jquery-min.js file and just want to access it via $ ) and use its available functions off the bat.

2) Injecting Code

If you want the code to be generated in your Haxe file rather than pointing to something external, you could inject code manually. Here’s an example (from my github page):

Unfortunately, code injection only works on cpp targets for now (android-native, iOS, desktop/mac).

What the code above basically does, is inject raw C++ code into the first line of the function’s {} block. Since you’re injecting code using string, you have to beware of typos and syntax errors yourself.

Note: The snippet above does not work on its own — you still have to write the native implementation of the code above, in the case above, you will need to have a WynGAKore.cpp  and WynGAKore.h  file. Check out my Github page for an idea of how the folders are structured.

3) Magic code

This is the easiest it seems. Here is an example:

Magic code is basically raw code injected via haxe. Similar to injecting code, you have to be wary of typos and syntax errors. Also, you need to use compiler flags when using magic code. E.g. If you’re building to android target, the __js__  code above will not work, and will throw an error.

Conclusion

I ended up having to use all three methods above. I use extern for javascript target, because it’s easier to just modify javascript files externally than to compile haxe->js repeatedly when debugging.

I use code injection to keep my .hx files intact, while being able to inject raw CPP code into the .hx functions. However, do remember that in my snippet above, I’m actually injecting some minor C++ code that call to the actual .cpp files’ functions. It’s a little long-winded, but the reason I’m doing this is to get the auto-completion to work in SublimeText. 🙂

I use magic code for small code snippets that don’t require any class, e.g. the js snippet above to get the window.location.href . I don’t get auto-completion for using magic code, so I need to be extra careful when using it.

Kha and Wyngine

When I first discovered Kha and experimented with it, the ride has been really bumpy. At the time, the author, Robert Konrad, had just started overhauling some parts of the Kha API, and it made things more frustrating as I was still transitioning between HaxeFlixel to Kha.

However, it seems that my decision to persevere is paying off. Not only did I learn a bunch of new things with Haxe itself, I managed to write a little game framework (or library, whichever the politically correct term is) on top of Kha, called Wyngine. Although Wyngine has been constantly evolving, the framework is starting to stabilise, and I have made two games out of it: Pollen and Hurdles.

I have also found it more comfortable to write code the “Haxe” way, as in raw code that’s not part of any library. When I started learning Haxe and HaxeFlixel, I was overwhelmed by the size of the HaxeFlixel API that I thought using anything outside of the library would cause something to break (yes, I made a very bad assumption, but who could have told me otherwise?).

After using Kha, I realise that I could literally write a game with just the basic APIs, without the fancy utility classes that came with OpenFL/HaxeFlixel. In a way, I felt liberated and gained a better understanding of the Haxe language itself. I’m no expert yet though — I still refer to the Haxe documentation on a daily basis.

Hopefully, the articles after this will dive a little on Kha, Wyngine, nuggets of wisdom in my journey of learning Haxe, and possibly simple tutorials on using Kha. For the moment, there’s other resources you can refer to, thanks to the die-hard Kha fans:

I know I’m missing out some links, but I’m sure if you Google it, you’ll find some resources or tutorials on Kha. The problem we have now is that the Kha community is really small, but on the bright side — they’re very dedicated! I’ve been hanging out on the IRC channel for the past few months, and I have been seeing the same names on the channel almost daily, and they are very helpful (whenever they’re not AFK, that is).

If you’re uncomfortable with Lime/OpenFL/HaxeFlixel/HaxePunk, Flambe, Snowkit/Luxe, or any other SDK, I highly recommend giving Kha a try — and if you like it, contribute to the github repo with bugfixes — because Robert is only one guy after all. 🙂

Happy New Year 2016

Happy (belated) New Year 2016! And now on to updates.

It seems I have abandoned HaxeFlixel almost completely in favour for Kha. Two months ago, I was in a limbo between using HaxeFlixel or Kha. Here is my list of pros-and-cons of using them. Note that these are my opinions after all, and YMMV (your mileage may vary):

  • HaxeFlixel pros
    • Very matured game framework
    • Has a lot of convenient libraries, e.g. Tiled parser, Nape integration, Quadtree collisions
    • One of the Haxe frameworks with large use-base (compared to OpenFL or HaxePunk)
    • Battle-tested to work and compile with minimal issues, since it originates from the Flixel framework.
    • Actively updated by the HaxeFlixel team, all of whom are very experienced.
    • Very, very easy to prototype platformers and other common 2D games.
  • HaxeFlixel cons
    • Bloated features – I doubt anyone uses about 80% of the library for prototyping purposes
    • Bloated classes – Too many properties; While this may not be significant, it can still be an issue for performance (CrossCode developers’ article on their experience with composite vs inherited classes) in the long run.
    • Bloated size – An empty HaxeFlixel game in HTML5 is a whopping 2MB, which is unacceptable for bite-sized games. Using minifiers reduces the size by half, but it still includes a lot of unnecessary code.
    • Difficult to find support – This is an anecdote — It’s tough to give and receive help when the only people who know their stuff are too busy fixing the core HaxeFlixel features, and the others are simply too busy working on their own games.
    • Experimental HTML5 support, with no WebGL support.
    • Attempting to tinker with HaxeFlixel’s code requires thorough knowledge of the underlying flow of Lime, OpenFL -and- HaxeFlixel. That’s a lot to stomach for me.
    • Doesn’t support shaders out of the box.
    • Doesn’t support 3D out of the box.
  • Kha pros
    • It’s an SDK similar to SDL for C++
    • One API for all targets
    • Almost native speed
    • Supports HTML5, WebGL with fallback on Canvas
    • Supports 2D and 3D.
    • Easier to dive into the code to tweak and make minor changes for custom builds.
    • Robert (the author of Kha) is super duper responsive, very helpful on the IRC channel, and knows his stuff.
  • Kha cons
    • The codebase is pretty volatile every now and then. This causes a lot of stuff to break frequently. Although, it’s somewhat stable now at version 16.1.
    • Kha is a work-in-progress, so expect some things to not be working yet, e.g. (anecdote, again) Audio on Chrome mobile is pretty bad.
    • Because Kha is an SDK rather than a game framework, you have to roll your own game engine or framework. On the positive side, this means you get full flexibility for how your app/game is written.
    • Since most of the work is done by Robert alone, updates may not come as fast as you’d expect. However, Robert looks at every single Pull Request and merges frequently, so contributions are greatly appreciated.
    • Lack of documentation. Although, you could always ask Robert directly (via twitter, IRC, or his forum) and he’ll get back to you pretty quick.

The comparison above may not seem fair, considering that Kha is more likened to Lime or OpenFL than HaxeFlixel, but even when I tried using Lime or OpenFL, Kha still feels a whole lot easier. I’m not exactly a great programmer, so if I can feel comfortable about Kha than I do with Lime or OpenFL, then it should speak volume.

Over the past two months of experimenting back and forth with Kha, and eventually rolling out my own game framework for Kha, Wyngine, I am quite content to say, I’m happy enough with my own lightweight component-based game framework. It’s missing a lot of the fancy stuff like Quadtrees (I removed it due to performance issues on mobile), Nape, animation, or Tiled parsers, but when I need them, I’ll definitely add those in.

Haxe Resources

I apologise for the really long absence. To be honest, I have been distracted by learning other stuff (ShaderToy, Kha, Snowkit, PhaserJS, Golang…), and so I’ve placed this blog on low priority since then.

In the meantime, I came across this new page that surfaced on Reddit: A compilation of Haxe resource links. One of the links point here too! You’ll notice there’s more Haxeflixel resource links there than any other framework at the moment, but do contribute to the list if you can:

http://haxeresource.meteor.com