All my games have some sort of framework, the way in which I add functionality to them, and whilst some may have been pretty simple, some have been planned using using tools such as UML diagrammes. For a while I used my own form of the MVC pattern as my framework, separating the games display from the games logic (something that should be adhered to in most if not all game development). Using this MVC method did allow me to do some cool things like swapping out a 2D top down view for an isometric view in UFO Abduction or swapping out the 2D view for a pseudo 3D view in Swamp Jumper, but I ended up having to write a lot of extra code and the game had to pass through lots of methods when running, I now generally do not think it is the “best” way to make games.
After deciding MVC was not the way to go, my game development took on a more classic “game loop” style, a central loop is called repeatedly, it loops through all the objects/entities in the game and updates them, checks for any collisions and then renders them. The entities would implement an interface and extend an abstract game entity for core functionality. I continued to rebuild this framework for each new game, each time improving upon the last framework, re-writing my collision detection methods, improving loop efficiency but although with each iteration the framework would become better, each game I was spending time writing boilerplate code when really I just wanted to be working on the game itself. So I decided to look at some third party game frameworks so I could focus on gameplay.
At the time there were three main Flash game frameworks or engines that people used, Flixel, FlashPunk and PushButton. My friend and colleague Duncan Sunders is a big advocate for Flixel which is more than just a framework, it is an engine and comes with all you need to make a game, collision detection, renderers etc.. Duncan uses Flixel for the majority of his games unless for some specific reason he can’t, and with tonnes of other games built using Flixel, I was well aware of its capabilities but I wanted to learn more about the other two less know frameworks.
I liked FlashPunk straight away, like Flixel it is a game engine but it is very lightweight and made from a small handful of classes. Also the FlashPunk framework was very (very) similar to how I was structuring my games and so I was up and running within minutes. What is also cool is the community surrounding FlashPunk, it has an active forum and it hosts regular FlashPunk game jams. I felt quite confident about setting FlashPunk as my defacto game framework/engine and planned to build Dalek Supremacy with it. But before I did, I just wanted to see what Push Button Engine had to offer.
I had previously watched a talk about PushButton Engine given by Ben Garney which is how I knew of it but didn’t see the potential at the time. The interesting thing about PushButton Engine (PBE) is that it uses an Entity/Component System instead of a classical inheritance based system, entities are given components rather than inheriting from parent classes (Unity3D uses a similar system). It was only after watching this video explaining the PBE component system (by Ben Garney) that I really got excited about PBE:
Firstly it favoured composition over inheritance, this is something that everyone goes on about and is preferable for many reasons as described in “the” Design Patterns book (Gang of Four). Secondly and more importantly to me, whilst developing Rizk I had fallen into the trap of needing a giant Abstract Entity (1:26) to accommodate all the game entities that were inheriting from it. Rizk took me several months to develop and over that time, it changed considerably, entities that once fired lasers from their eyes, now generated shields, others turned into suicide bombers, at one time they all walked, then they could fly and to accommodate all this, the abstract/base class kept growing and each time I added a new feature, I had to check it was okay with all the other entities.
With a component system this would not have happened, and so I got quite excited about it and began to read reading everything I could find including this great blog post over at www.learn-cocos2d.com, it also has a link to lots of talks and papers on the subject, which I have mostly added here:
So I got stuck in and soon had a little demo up and could see the potential. Although it did seem like a lot of extra code to get started, (I was creating all my entities and components in actionscript rather than using the xml method) I knew the end result would be worth it and so before I was due to start work on Dalek Supremacy I decide to quickly try prototyping it in PBE. All was going well untill I ran into some problems and although the PBE community was very enthusiastic and helpful, my forum post didn’t get answered for around 48 hours which may not seem that long but on a client job, I could not afford to be sitting around waiting for help. I also tried the PushButton irc channel but there were only a few people ever online, one of the problems of being a UK developer when everyone else is in the US but also a sign that the community is too small to really rely upon when deadlines are concerned. In the end, although I did get an answer to my my question I could not run the risk of developing a game with a client deadline using PushButton, but I liked it so much that I decided I would have to build my own, one that I would know inside out.