Base class for everything that lives in the scene.
More...
#include <game_object.hpp>
Base class for everything that lives in the scene.
A game object is a container of IComponent instances. It exposes a type-safe component API (appendComponent, getComponent, newComponent, ...) and lifecycle hooks (onUpdate, onMouseEvent, onEnable, onDisable) that subclasses may override. Managed by the ObjectManager.
◆ GameObject()
| cangine::GameObject::GameObject |
( |
| ) |
|
◆ ~GameObject()
| cangine::GameObject::~GameObject |
( |
| ) |
|
|
virtual |
◆ appendComponent()
| void cangine::GameObject::appendComponent |
( |
T * |
component | ) |
|
|
inline |
Attaches an existing component to this object.
Calls the component's IComponent::firstFrame once attached. Asserts if a unique component of the same type already exists.
- Template Parameters
-
- Parameters
-
| component | Component instance to attach (ownership taken). |
◆ destroy()
| void cangine::GameObject::destroy |
( |
| ) |
|
|
inline |
◆ destroyComponent()
| void cangine::GameObject::destroyComponent |
( |
| ) |
|
|
inline |
Destroys and removes the first component of a type.
- Template Parameters
-
| T | Component type to remove. |
◆ getComponent()
| T * cangine::GameObject::getComponent |
( |
| ) |
|
|
inline |
Returns the first attached component of a type.
- Template Parameters
-
- Returns
- Pointer to the component, or
nullptr if none.
◆ getComponents()
| std::vector< T * > cangine::GameObject::getComponents |
( |
| ) |
|
|
inline |
Returns all attached components of a type.
- Template Parameters
-
- Returns
- Vector of matching components (possibly empty).
◆ isActive()
| bool cangine::GameObject::isActive |
( |
| ) |
|
Reports whether the object is active.
- Returns
true if active.
◆ newComponent()
| T * cangine::GameObject::newComponent |
( |
Args &&... |
args | ) |
|
|
inline |
Constructs a component in place and attaches it.
- Template Parameters
-
| T | Component type to create. |
| Args | Constructor argument types. |
- Parameters
-
| args | Arguments forwarded to the component's constructor. |
- Returns
- Pointer to the newly created component.
◆ onDisable()
Called when the object becomes inactive.
Reimplemented in cangine::Panel.
◆ onEnable()
Called when the object becomes active.
Reimplemented in cangine::Panel.
◆ onMouseEvent()
Mouse event hook.
- Parameters
-
| e | The mouse event delivered to this object. |
◆ onUpdate()
| void cangine::GameObject::onUpdate |
( |
double |
deltaTime | ) |
|
|
virtual |
Per-frame update hook.
- Parameters
-
| deltaTime | Seconds elapsed since the previous frame. |
◆ setActive()
| void cangine::GameObject::setActive |
( |
bool |
a | ) |
|
Activates or deactivates the object.
- Parameters
-
| a | true to enable, false to disable. |
◆ ObjectManager
◆ active
Whether the object is active (updated/drawn).
◆ components
| std::vector<IComponent*> cangine::GameObject::components |
|
private |
Components attached to this object.
◆ pendingDestroy
| bool cangine::GameObject::pendingDestroy = false |
|
private |
Whether the object is queued for destruction.
The documentation for this class was generated from the following files: