-
Notifications
You must be signed in to change notification settings - Fork 2
GameObject
GameObject is a generic type for an object that has some function in the game world itself. Typically GameObjects are used as mere containers for Components that define their behavior and functionality.
If it's needed however, you can add some special functionality for a GameObject itself by deriving the class and overriding the update and draw methods (note that these are uncapitalized).
GameObjects have a parent-child system, which means that for any object, you can add children in as many layers (or "generations") as you want.
To update/draw all the objects bound together you only need to call the appropriate function from the top-most object. Changes to a parent's transform will be reflected in its children.
Components (Main page)
The functionality of a GameObject is ideally defined by what components it has.
-
You can add a new component using
AddComponent, which takes a pointer to a component allocated in heap. -
To query for a component you need to use either:
-
<T>GetComponent(), where T is the type of the component. -
<T>GetComponent(const std::string& name), where T is the type of the component andnameis the name of the component. Note that this overload ignores type information and should only be used when you're sure the type matches the template argument.
-
-
To remove components you need to use either:
-
RemoveComponent(Component* component), wherecomponentis a pointer (address) of the component you want to remove -
RemoveComponent(const std::string& name), wherenameis the name of the component. -
RemoveComponents(), which deletes all components.
-