Jump to content

  • Log In with Google      Sign In   
  • Create Account

Frostraver

Member Since 27 Mar 2012
Offline Last Active Yesterday, 08:55 AM

#5085027 How to implement a Component-Based Entity system?

Posted by Frostraver on 11 August 2013 - 03:30 PM

Maybe this isn't a good explanation for your problem but have you taken a look at Unity (the game engine)?

They use component-based entities as well.

 

As for the programming part, there possibly are some engines that use this method that are open-source.

 

What would do is create a base class called, for example, BaseComponent and then create a lot of components that you want to use that use BaseComponent as their parent class. Then you'll need some kind of base class that resembles the basic of an Object to which you want to add components, just like in Unity. Let's call it GameObject.

 

Now you can create seperate objects that all use GameObject as their parent class. In this class you'll have an array of components. So, you can create a new component and afterwards add it to the array of components of a specific GameObject.

 

Say you added a component that holds the transformations of an object. You could, for example, scale the object by doing the following: 

gameObject->GetComponent<TransformComponent>()->Scale(5.0f);

That would scale the gameObject 5 times it's normal size.

 

That's basically how it works.




PARTNERS