What’s in an Entity

I’ve been working on a game engine lately. More to the point I’ve been thinking about game entities and how they all fit together. It occurred to me that I had a pretty poor system in the past, for instance in Shade, and I think I’ve since made some conceptual advances which I thought I’d share:

Four Types of Entities Types of Entities

This table pretty much says it all, but I’ll flesh it out just in case. In the past I had a single type of entity represented by the Entity class or interface. At some point I needed entities to collide with each other so I added a Body class. In practice, every body was an entity and vice versa. This lead to some problems. For instance, in order to handle score bubbles in Shade I needed to create a custom class and then manage it from some control. Not only was this awkward but it meant that if I wanted to add score bubbles to other things I would need to copy and paste all of the bookkeeping code. The problem was I didn’t have a notion of an active-intangible entity.

Fortunately, the solution is straightforward. Instead of treating every object as something which needs to be updated and is checked for collisions split your game’s objects into four categories. Right now I’m finding that some objects, such as triggers for events, are tangible but not active entities. Others, such as controls to generate new monsters, are active but intangible entities. With this new framework I’m able to represent all of these cases without having to create a parallel hierarchy to accommodate them. And not only does this clean things up conceptually but it also offers an opportunity to improve performance. With this distinction you only need to update entities which actually require it, likewise for collision detection, and you can even have objects in your game which are added once and then ignored.

Anyway, I hope that you find this distinction useful in your next game. Feel free to let me know if you’d like to see some more examples of how this works in practice.

Comments

2 Responses to “What’s in an Entity”
  1. Mike says:

    I am approaching a point in my development of classes I’m writing on the iPhone to think about game entities. Your description above is interesting and I’d certainly be interested to hear more about how you see this working in practice.

    Regards

    Mike

  2. aschearer says:

    Hey Mike, I’d be happy to share. So far I’ve used the above setup in a flash game. In flash a Sprite or Movieclip defaults to being a Passive-Intangible entity — that is it simply has a position in space and renders to each frame. So all I needed to do was define what Tangible and Active entities are.

    So far the division of responsibility has been very helpful. For instance, I have two types of scritable events: ones which are fired when some physical event occurs and those which are fired when some non-physical event occurs. This maps directly to the Tangible-Active paradigm meaning that I didn’t have to diverge from my core interfaces when implementing my scripting engine.

    Anyway feel free to follow up with some more questions if you have them.

Leave A Comment