Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've read some about component-based game design but am still having some trouble figure out how exactly you'd go about implementing it. Are there any good examples of component-based games or game engines that I could read through to get a better feel for this?

share|improve this question
add comment

4 Answers 4

Another one, I haven't used, but looked through the code a bit, is Artemis. Well commented and quite active. Originally a Java framework but has been ported to C#/XNA.

share|improve this answer
add comment

Personally I don't think there are any good examples, largely because the definition of a "component-based system" for games is so loosely defined that it can mean next to nothing.

You might find some of the discussion in this answer helpful: How to implement a component based system for items in a web game.

On the whole though, the approach is simply to change any sort of GameObject or Actor from a large class that handles all behaviour into a simpler class that holds objects that perform behaviour. I think that working through this yourself and making different components that suit your game will often be the best way to proceed.

share|improve this answer
    
I hear that. When trying to find good resources on it, I found that almost every person use different terminology to describe things. Made it hard to compare different implementations when you spend half the time translating the basic structures. Entity System, Component System, Game Object, Template, Assembly, Component Assemblage, etc... –  Leniency Mar 13 '11 at 6:38
add comment

This site starts into a basic implementation.

Most of the above is inspired by this article at T=Machine

I started into a basic implementation inspired by the above two links. I'm pretty sure I've deviated a lot from the pure theory of component systems, and there undoubtedly bugs, but it might prove useful if you're looking for some simple examples.

Bricle (C#/XNA)

Right now it's just loading up some basic entities, handles some events, etc. The main locations you're looking for are the Engine.EntitySystem folder and probably the PlayScreen where entities are actually created.

Creating a simple type-based component store and hiding that behind a common EntityManager was relatively straight forward.

The first challenge I ran into was when individual systems might require multiple component types (ie, Physical components and InputMoveable). To use the relational database language, I had to find a way to do a JOIN query. For that, I made another collection type for entities built from the matching component type queries - each entity collection hooks into an OnEntityCreate event and checks if it matches. Still some bugs there.

The second challenge was actually creating a 'game object' - I called them templates. Here I'm probably not very pure according to T=Machine's specs, but it seems to work. Templates group together component instantiations and allow easier entity composition (ie, the Ball is Drawable and Physical).

Hope that's helpful - entity/component systems can be a challenge to get through some of the initial hurdles.

share|improve this answer
add comment

Here are some resources you may like:
There's this amazing thread. It's not a game engine itself, but the design and discussion is great.
A question on StackOverflow on a very similar topic.

To answer the original question, the Elephant framework in C# is precisely what you want: it has been discontinued, but still exists here for reference of implementation.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.