Practical Tools for Simple Design
Loading...
Searching...
No Matches
Util::GameObject Class Reference

A class representing a game object. More...

#include <GameObject.hpp>

Public Member Functions

 GameObject ()=default
 Default constructor.
 
 GameObject (const std::shared_ptr< Core::Drawable > &drawable, const float zIndex, const glm::vec2 &pivot={0, 0}, const bool visible=true, const std::vector< std::shared_ptr< GameObject > > &children=std::vector< std::shared_ptr< GameObject > >())
 Parameterized constructor. More...
 
 GameObject (const GameObject &other)=default
 Copy constructor. More...
 
 GameObject (GameObject &&other)=default
 Default move constructor..
 
virtual ~GameObject ()=default
 Default destructor.
 
GameObjectoperator= (const GameObject &other)=delete
 
float GetZIndex () const
 Get the z-index of the game object. More...
 
Transform GetTransform () const
 Get the transform of the game object. More...
 
glm::vec2 GetScaledSize () const
 Get the size of its drawable component. More...
 
const std::vector< std::shared_ptr< GameObject > > & GetChildren () const
 Get the children of the game object. More...
 
void SetPivot (const glm::vec2 &pivot)
 Set the pivot of the game object. More...
 
void SetZIndex (float index)
 Set the z-index of the game object. z-index is used to determine the order in which game objects are drawn, the greater z-index, the topper the its Util::Drawable is. More...
 
void SetDrawable (const std::shared_ptr< Core::Drawable > &drawable)
 Set the drawable component of the game object. More...
 
void SetVisible (const bool visible)
 Set the visibility of the game object. More...
 
void AddChild (const std::shared_ptr< GameObject > &child)
 Add a child to the game object. More...
 
void RemoveChild (const std::shared_ptr< GameObject > &child)
 Remove a child from the game object. More...
 
void Draw ()
 

Public Attributes

Util::Transform m_Transform
 

Protected Attributes

std::shared_ptr< Core::Drawablem_Drawable = nullptr
 
std::vector< std::shared_ptr< GameObject > > m_Children
 
float m_ZIndex = 0
 
bool m_Visible = true
 
glm::vec2 m_Pivot = {0, 0}
 

Detailed Description

A class representing a game object.

This class encapsulates the properties and behaviors of a game object.

Note
This is an abstract class. Inherit from this class to create your own game objects.

Constructor & Destructor Documentation

◆ GameObject() [1/2]

Util::GameObject::GameObject ( const std::shared_ptr< Core::Drawable > &  drawable,
const float  zIndex,
const glm::vec2 &  pivot = {0, 0},
const bool  visible = true,
const std::vector< std::shared_ptr< GameObject > > &  children = std::vector<std::shared_ptr<GameObject>>() 
)
inline

Parameterized constructor.

Parameters
drawableThe Util::Drawable component of the game object.
zIndexThe z-index of the game object.
visibleThe visibility of the game object.
childrenThe children of the game object.

◆ GameObject() [2/2]

Util::GameObject::GameObject ( const GameObject other)
default

Copy constructor.

Parameters
other
Note
This is a shallow copy constructor, meaning the m_Drawable points to the same reference as same as other's does.

Member Function Documentation

◆ AddChild()

void Util::GameObject::AddChild ( const std::shared_ptr< GameObject > &  child)
inline

Add a child to the game object.

Parameters
childThe new child of the game object.

◆ GetChildren()

const std::vector< std::shared_ptr< GameObject > > & Util::GameObject::GetChildren ( ) const
inline

Get the children of the game object.

Returns
The children of the game object.

◆ GetScaledSize()

glm::vec2 Util::GameObject::GetScaledSize ( ) const
inline

Get the size of its drawable component.

Returns
vec2(x, y) representing the size of the drawable component.

◆ GetTransform()

Transform Util::GameObject::GetTransform ( ) const
inline

Get the transform of the game object.

Returns
The transform of the game object.

◆ GetZIndex()

float Util::GameObject::GetZIndex ( ) const
inline

Get the z-index of the game object.

Returns
The z-index of the game object.

◆ RemoveChild()

void Util::GameObject::RemoveChild ( const std::shared_ptr< GameObject > &  child)
inline

Remove a child from the game object.

Parameters
childThe child to be removed.

◆ SetDrawable()

void Util::GameObject::SetDrawable ( const std::shared_ptr< Core::Drawable > &  drawable)
inline

Set the drawable component of the game object.

Parameters
drawableThe new drawable component of the game object.

◆ SetPivot()

void Util::GameObject::SetPivot ( const glm::vec2 &  pivot)
inline

Set the pivot of the game object.

Parameters
pivotThe pivot of the game object.

◆ SetVisible()

void Util::GameObject::SetVisible ( const bool  visible)
inline

Set the visibility of the game object.

Parameters
visibleThe new visibility of the game object.

◆ SetZIndex()

void Util::GameObject::SetZIndex ( float  index)
inline

Set the z-index of the game object. z-index is used to determine the order in which game objects are drawn, the greater z-index, the topper the its Util::Drawable is.

Parameters
indexThe new z-index of the game object.

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