Why use an entity system framework for game development?

Following my previous post on entity systems for game development I received a number of good questions from developers. I answered many of them in the comments on that post, but one question stands out. It’s all very well explaining what an entity system framework is, and even building one, but why would you want to use one? In particular, why use the later component/system architecture I described and that I implement in Ash rather than the earlier object-oriented entity architecture as used, for example, in PushButton Engine.

So, in this post I will look more at what the final architecture is, what it gives us that other architectures don’t, and why I personally prefer this architecture. Continue reading

What is an entity system framework for game development?

Last week I released Ash, an entity system framework for Actionscript game development, and a number of people have asked me the question “What is an entity system framework?”. This is my rather long answer.

Entity systems are growing in popularity, with well-known examples like Unity, and lesser known frameworks like Actionscript frameworks Ember2, Xember and my own Ash. There’s a very good reason for this; they simplify game architecture, encourage clean separation of responsibilities in your code, and are fun to use.

In this post I will walk you through how an entity based architecture evolves from the old fashioned game loop. This may take a while. The examples will be in Actionscript because that happens to be what I’m using at the moment, but the architecture applies to all programming language. Continue reading

Ash – a new entity system framework for Actionscript games

I’ve been doing a lot of stuff with entity systems recently. At try{harder} I gave a presentation about entity systems, which was warmly received and led to many interesting conversations. I also created example projects with the Ember and Xember frameworks and had fruitful conversations with Tom and Alec about their projects, even contributing a few minor bits of code to them.

But now I’ve written an entity system framework of my own. It’s called Ash and you can find it on Github. Continue reading

Four ways to link a list (a performance test on linked list architectures)

In looking at entity systems for Flash games, and particularly the projects Ember and Xember, I was wondering what is the most efficient architecture for the linked lists used by these systems. So I ran some tests.

The code for these tests is all available on Github.

The lists in these frameworks are used to manage the component sets for the systems that run the game. These lists need to provide three functions – add an item, remove an item, and loop through all the items, and they need to do this as efficiently as possible.

So I created four different architectures for linked lists and ran a few performance tests. Continue reading

Polling the keyboard in Actionscript 3

Games often need to get the current state of various keys in order to respond to user input. This is not the same as responding to key down and key up events, but is rather a case of discovering if a particular key is currently pressed.

In Actionscript 2 this was a simple matter of calling Key.isDown() with the appropriate key code. But in Actionscript 3 Key.isDown no longer exists and the only intrinsic way to react to the keyboard is via the key up and key down events.

To rectify this I created the KeyPoll class, which has isDown and isUp methods, each taking a key code as a parameter and returning a Boolean. The class is in my GitHub code repository.

Using the class looks like this

  import flash.display.Sprite;
  import flash.events.Event;
  import flash.ui.Keyboard;
  import net.richardlord.input.KeyPoll;

  public class Test extends Sprite {
    var key:KeyPoll;

    public function Test() {
      key = new KeyPoll( this.stage );
      addEventListener( Event.ENTER_FRAME, enterFrame );

    public function enterFrame( ev:Event ):void {
      if( key.isDown( Keyboard.LEFT ) ) {
        trace( "left down" );
      if( key.isDown( Keyboard.RIGHT ) ) {
        trace( "right down" );

The constructor for the KeyPoll class takes a single parameter which is a DisplayObject on which the KeyPoll object should listen to keyboard events. To listen globally to all keyboard input this should be the stage, as in the example.

The class uses a ByteArray to hold the current keyboard state, which is updated in response to Keyboard events and queried by the public methods, isDown and isUp. Using a ByteArray is more compact than using an Array of Booleans, and in tests it also turned out to be marginally faster, although the difference in speed was not significant enough to matter.

Further, the class clears the key state array when the deactivate event occurs, so key state is not retained if the Flash Player loses focus and stops receiving keyboard input.

Physics for Flash Games: Slides

It was great to see so many people at my presentation yesterday at LFPUG. The presentation seemed to go down very well and I had a great evening. Here’s the slides from my presentation. If you weren’t there, they may not make a lot of sense without my talking over the top of them, but I suspect lots of people who were there want to look at the code again.

The presentation is driven entirely from the keyboard arrow keys – left and right to move through the slides and up and down to scroll the text in the code displays.

Click here for the slides (flash required)

Physics for Flash Games

On Thursday this week, I’m doing a presentation on Physics for Flash Games at the London Flash Platform User Group. It’s a tricky presentation to plan because there’s such a wide range of knowledge and ability among the audience but I think I’ve come up with a presentation that has something for everyone. Hope to see lots of London Flash users there. There’s no membership requirement so if you’re interested just turn up. Or better still sign up on the web page because then you have a chance to win one of the prizes in the raffle.

The slides from this talk are now online here.