Turbo Engine 0.3
A C++ game engine using Allegro 5
turbo::GameObject Class Referencefinal

Basic scene object. More...

#include <GameObject.hpp>

Inheritance diagram for turbo::GameObject:
Collaboration diagram for turbo::GameObject:

Public Member Functions

 GameObject (GameObject *parent, std::string name)
 Construct a new GameObject object.
 ~GameObject ()
 GameObject (const GameObject &)=delete
GameObjectoperator= (const GameObject &)=delete
void add_component (Component *comp)
 Add a component to the GameObject.
void remove_component (Component *comp)
 Remove a component to the GameObject.
unsigned short get_component_amount () const
void render (void *transform)
void update (int delta_time)
void set_drawable (Drawable *drawable)
Drawableget_drawable () const
void set_material (Material *material)
 Material applied to the drawable when rendering (null = default). Not owned: materials are shared and owned by the ShaderLibrary.
Materialget_material () const
 Material currently applied to the drawable (null = default).
std::string get_name () const
bool set_name (const std::string &name)
 Rename the object. Fails (returns false) if a sibling already uses that name or the name is empty.
GameObjectget_parent () const
 Get the parent GameObject (null for the scene root).
void attach_to (GameObject *parent)
 Re-parent this object (detaching from its current parent first). Passing nullptr detaches it from the hierarchy without destroying it.
template<typename T, typename = std::enable_if_t<std::is_base_of_v<Component, T>>>
T * get_component ()
 Get the component object.
Public Member Functions inherited from turbo::Transform
 Transform ()=default
 Transform (const Vector2< float > &position, float angle=0, const Vector2< float > &scale=Vector2< float >(1, 1), const Vector2< int > &center=Vector2< int >())
 Transform (float x, float y=0, int scaleX=1, int scaleY=1, float angle=0, int centerX=0, int centerY=0)
 ~Transform ()=default
void translate (float x, float y)
 Translate the object in 2D.
void translate (const Vector2< float > &offset)
 Translate the object in 22.
void set_position (float x, float y)
 Set the position of the object.
void set_position (const Vector2< float > &pos)
 Set the position of the object.
void rotate (float deg)
 Rotate the current object by deg degrees.
void set_rotation (float deg)
 Set the rotation of the object.
void set_center (int x, int y)
 Set the center of rotation of the object (Start in 0,0 , position in pixel).
void set_center (const Vector2< int > &center)
 Set the center of rotation of the object (Start in 0,0 , position in pixel).
void set_scale (const Vector2< float > &scale)
 Set the scale of the object (base scale == 1.0).
void set_scale (float scale_x, float scale_y)
 Set the scale of the object (base scale == 1.0).
const Vector2< float > & get_position () const
const Vector2< float > & get_scale () const
const Vector2< int > & get_center () const
float get_angle () const

Public Attributes

bool show = true
std::vector< GameObject * > childs {}
std::vector< Component * > components {}

Additional Inherited Members

Protected Member Functions inherited from turbo::Transform
ALLEGRO_TRANSFORM * get_transformer ()
Protected Attributes inherited from turbo::Transform
float angle = 0
 angle of the object
Vector2< float > position = Vector2<float>()
Vector2< float > scale = Vector2<float>(1, 1)
Vector2< int > center = Vector2<int>()
ALLEGRO_TRANSFORM transform {}
bool property_has_changed = true
Static Protected Attributes inherited from turbo::Transform
static ALLEGRO_TRANSFORM default_transform = ALLEGRO_TRANSFORM()

Detailed Description

Basic scene object.

Constructor & Destructor Documentation

◆ GameObject() [1/2]

turbo::GameObject::GameObject ( GameObject * parent,
std::string name )
explicit

Construct a new GameObject object.

Parameters
parentparent GameObject or null if root node
nameGameObject name

◆ ~GameObject()

turbo::GameObject::~GameObject ( )

◆ GameObject() [2/2]

turbo::GameObject::GameObject ( const GameObject & )
delete

Member Function Documentation

◆ add_component()

void turbo::GameObject::add_component ( Component * comp)

Add a component to the GameObject.

Parameters
compcomponent instance

◆ attach_to()

void turbo::GameObject::attach_to ( GameObject * parent)

Re-parent this object (detaching from its current parent first). Passing nullptr detaches it from the hierarchy without destroying it.

◆ get_component()

template<typename T, typename = std::enable_if_t<std::is_base_of_v<Component, T>>>
T * turbo::GameObject::get_component ( )
inline

Get the component object.

Template Parameters
TType of component
Returns
T* instance of the component

◆ get_component_amount()

unsigned short turbo::GameObject::get_component_amount ( ) const

◆ get_drawable()

Drawable * turbo::GameObject::get_drawable ( ) const

◆ get_material()

Material * turbo::GameObject::get_material ( ) const

Material currently applied to the drawable (null = default).

◆ get_name()

std::string turbo::GameObject::get_name ( ) const

◆ get_parent()

GameObject * turbo::GameObject::get_parent ( ) const

Get the parent GameObject (null for the scene root).

◆ operator=()

GameObject & turbo::GameObject::operator= ( const GameObject & )
delete

◆ remove_component()

void turbo::GameObject::remove_component ( Component * comp)

Remove a component to the GameObject.

Parameters
compcomponent instance

◆ render()

void turbo::GameObject::render ( void * transform)

◆ set_drawable()

void turbo::GameObject::set_drawable ( Drawable * drawable)

◆ set_material()

void turbo::GameObject::set_material ( Material * material)

Material applied to the drawable when rendering (null = default). Not owned: materials are shared and owned by the ShaderLibrary.

◆ set_name()

bool turbo::GameObject::set_name ( const std::string & name)

Rename the object. Fails (returns false) if a sibling already uses that name or the name is empty.

◆ update()

void turbo::GameObject::update ( int delta_time)

Member Data Documentation

◆ childs

std::vector<GameObject*> turbo::GameObject::childs {}

◆ components

std::vector<Component*> turbo::GameObject::components {}

◆ show

bool turbo::GameObject::show = true

The documentation for this class was generated from the following files: