Now a GitHub Page

21 Apr 2014

So I've joined the GitHub Pages/Jekyll revolution - I've ditched WordPress in favour of a git based workflow, writing simple Markdown documents to create posts. Hopefully the decreased friction in writing posts will actually encourage me to write things. I'm writing this in GitHub's Atom editor, to then use git to commit and push it to GitHub and it feels like git is pervading every element of my life!

I threw together some HTML/CSS based on the default Jekyll page and this is what happened. It looks like a sedate Geocities page and I love it. Retro-functional-chique.

JSON Is Driving My New Game

27 Jan 2014

I've begun work on a game idea that's been bouncing off the inside wall of my brain for a couple of years now. I'm (obviously) convinced it's going to be the greatest thing that's ever been achieved by any being so I won't go into any gameplay details until I actually have something to show of it. There's going to be a lot of systemsy stuff in it, so I've implemented an entity/component system (or ECS) in Haxe. This enables me to write my code in terms of Entities, Components and Systems. My Entities are (more or less) a collection of Components. My Systems register interest with combinations of Components so that they can be notified when a relevant Entity becomes active and can then manipulate is as appropriate. For example my TouchSystem is interested in Entities that have a TouchableComponent and a SpriteComponent (so they know how big the touchable area for the entity is).
One interesting outcome of this approach is it keeps the data very separate from the functionality - Components are just dumb data holders, while the Systems provide the functionality, based on Component composition. I had a plan about how I could leverage this...

I've used Unity quite a bit, both professionally and for-funsies, and really appreciate its editor. It gives you the ability to build entities out of components with a drag and drop interface, the effects of which can be seen before you very eyes over in the live-updating 3D views. While I have no intention of writing a full editor for my game I wanted to achieve some degree of development, beyond just level editing, without having to touch the code. I'm using OpenFLTiled to allow me to import Tiled maps into my game. Tiled also lets you add arbitrary string to string key-value data to the map and its objects. My plan was this: store the types of components, and their initial data, right there in the map.
I implemented a step in the loading of the level that will iterate through the objects in the map and get hold of all the data they store. For each object I spawn an entity. For each key-value pair I use the key as a string representation of a type of component (literally its class name). The value is interpreted as a JSON array, and I get back a bunch of values. Haxe has extensive reflection support, so I instantiate the component based on its class name, and pass the deserialised JSON array along to the constructor to build the component just from data stored in the Tiled map. In the map's data (as opposed to the objects in it) I specify a list of Systems to instantiate for this map (so we could turn off the Physics system for specific maps, for example). So now we can build unique combinations of Components right in Tiled. This is the main advantage ECS has over OO: we don't have to extend anything to add functionality - it's all based on run time composition. We can then specify which Systems we want to exist, save it and run the game. Once I have a good library of Components and Systems implemented I can see this leading to a very Unity-like(-a-bit), editor driven workflow for Super Secret Game X.

On Posting

27 Jan 2014

I often think about writing more on this here internet, but quickly dismiss the idea, thinking that what’s on my mind is trivial and obvious and of use to no one. Lately I’ve been considering the type of people who would actually read any of the content I’m ever likely to post and my opinion has changed: if you’re reading this you might find stuff I’m implementing in my projects new, interesting or at least vaguely applicable. It doesn’t have to be ground breaking and it might just inspire someone to try a different approach to their development. With that in mind I’m going to endeavour to post more, starting with the thing that will follow shortly!

Dirty Haxe

08 Aug 2013

I'm working on my first ever Haxe project and I am loving it. Haxe is a free, open source, object-oriented, cross platform, multi-target, ActionScript-like language and compiler. From one project you can generate:

  • a compiled SWF, with support for a bunch of Flash versions
  • JavaScript
  • PHP
  • C#, for targeting Windows,Windows Phone, Xbox or anything Mono supports
  • Java, for targeting Android or anything that runs the JVM
  • C++, for targeting basically anything else

Apart from SWF these will all provide source code which can then be built in an environment of your choosing.

What about making games?

For me, the real magic comes with the OpenFL library - an open source, cross platform implementation of the Flash standard library. This gives you access to a complete, well documented node based view hierarchy that can target basically anything. From the same project, using a different build argument, OpenFL can build to run in browser using HTML5 or Flash; natively on Windows, Mac and Linux desktop; on mobile, with support for iOS, Android and BlackBerry. This means you can hedge your bets when targeting browser: don't want to worry about flakey HTML5 support? Provide it as an option, but also build a SWF for everybody else. There's always going to be discrepancy between hardware and screen resolutions available on different mobile devices, but that doesn't mean you need different code. Build support for different resolutions into your game and target standard hardware features and your game can run on anything.

The language

So it can build a game to run on your toaster, but how is it to actually use? Well, for a start it has a compiler, so you know ahead of execution that your local variable is being used without being assigned. It's strictly typed, so that same compiler can catch you assigning a String to an Int. It also makes good use of type inference so you still don't have to be too verbose with assignment. It supports generics for some sweet strictly-typed containers. It supports anonymous functions and function objects for super-convenient callbacks. It's got a thorough standard library with support for sockets, web requests, XML parsing, functional-style set manipulation and a bunch more. The standard library support varies depending on what's actually available on different platforms, but that's all covered in the API docs. I haven't had to touch too much of it for the project I've been working on, but the hash map implementation has served me well. Compile times are an oft-quoted boon of Haxe, and from my limited experience it seems great. My MacBook Air generates the JS target for my simple puzzle games in 2-3 seconds.

I've struggled a little bit with debugging but that's mainly a result of targeting HTML5. The JavaScript debugger in Firefox is great but you're debugging a single monolithic JS file which is a different representation of your Haxe code, and then figuring out what that actually translates to. I'll have to explore further if there's a way to debug something closer to the actual game code I wrote, ideally the Haxe code itself. Declarations are ECMAScript style, name:Type (e.g. var x:Int), which I find a little off-putting as I spend most of my time in C-like languages, but I can cope!


I use Unity extensively, both at work and at home, and it's perfect for making cross-platform 3D games, making heavy use of the concept of scenes. I've made a few 2D games in Unity and it always feels like I'm fighting against it, shoehorning 2D elements into a 3D workflow. Haxe with OpenFL seems like a great code-centric alternative to Unity - you get all the benefits of write-once, deploy anywhere, plus the whole Flash standard library to drive your game's sprites. I'll definitely be using it for any small 2D games I make in the near future. Also having the option of targeting Flash is a nice bonus few other cross platform solutions still support!

Events Are Operational

18 Feb 2013

I have implemented my proposal outlined in the previous post and all it's working great. There's a base TriggerComponent class which holds a pointer to its action. PositionTriggerComponent extends TriggerComponent, and PositionTriggerSubSystem checks for objects occupying PositionTriggerComponent-Entities' tiles and sets the triggered flag on their Actions. Finally, classes inheriting from ActionSubsystem decide how to handle their actions being triggered. This is working for a simple DebugActionComponent/SubSystem but the idea should apply to anything else. Getting closer to being able to make a game.