jade-engine  0.0
JadeEngine::IGameObject Class Reference

#include <IGameObject.h>

Inheritance diagram for JadeEngine::IGameObject:
JadeEngine::Button JadeEngine::Checkbox JadeEngine::Dropdown JadeEngine::FTC JadeEngine::LineBox JadeEngine::LineGrid JadeEngine::LineStrip JadeEngine::ProgressBar JadeEngine::Slider JadeEngine::Sprite JadeEngine::Text JadeEngine::TextBox JadeEngine::Tooltip JadeEngine::TransformGroup

Public Member Functions

 IGameObject ()
 
virtual void Update ()
 
virtual void Clean ()
 
virtual LoadState Load (SDL_Renderer *renderer)
 
virtual void Render (SDL_Renderer *renderer)
 
LoadState GetLoadState () const
 
void SetLoadState (const LoadState newState)
 
bool IsShown () const
 
virtual void Show (const bool show)
 
int32_t GetZ () const
 
void Destroy ()
 
bool DestructionWanted () const
 

Public Attributes

const std::shared_ptr< Transformtransform
 

Protected Attributes

LoadState _loadState
 
bool _shown
 
int32_t _z
 

Detailed Description

Interface for game objects.

The most basic building block of Jade Engine, game objects are objects that live inside a scene and can be updated and rendered every frame.

Additionally game objects can be used to compose simple game objects into more advanced ones. For example a Button game object will have collection of Sprite game objects for various pressed states and a Text game objects.

When creating new game objects based on IGameObject it is necessary to create a constructor that accepts only one argument: constant reference to creation structure which will contain at the very least ObjectLayer layer; member. See following example:

#include "IGameObject.h"
#include "ObjectLayer.h"
using namespace JadeEngine;
namespace JadeEngine
{
class Sprite;
}
struct SomeObjectParams
{
ObjectLayer layer; // Required
// Other parameters necessary to initialize the _childSprite and other child objects
};
class SomeObject : public IGameObject
{
public:
SomeObject(const SomeObjectParams& cardParams); // Create _childSprite and other child objects in here
void Update() override; // Perform frame logic here
private:
Sprite* _childSprite;
};
See also
IScene, Game::Create

Constructor & Destructor Documentation

◆ IGameObject()

JadeEngine::IGameObject::IGameObject ( )
inline

Default constructor for game object.

Member Function Documentation

◆ Clean()

virtual void JadeEngine::IGameObject::Clean ( )
inlinevirtual

Triggered when the game object is about to be destroyed or reset.

All resources belonging solely to the game object, such as textures, should be released at this point. The game object instance itself may or may not be destroyed after this callback.

Reimplemented in JadeEngine::Sprite, JadeEngine::Text, and JadeEngine::TextBox.

◆ Destroy()

void JadeEngine::IGameObject::Destroy ( )
inline

Mark the object to be destroyed.

At the begging of the next frame its Clean function will be called and the game object will removed from list of game objects.

◆ DestructionWanted()

bool JadeEngine::IGameObject::DestructionWanted ( ) const
inline

Returns whether the object is marked for destruction.

◆ GetLoadState()

LoadState JadeEngine::IGameObject::GetLoadState ( ) const
inline

Return the current load state of the game object.

See also
LoadState

◆ GetZ()

int32_t JadeEngine::IGameObject::GetZ ( ) const
inline

Returns Z coordinate. The game objects with higher Z coordinate will be drawn over the ones with lower one.

◆ IsShown()

bool JadeEngine::IGameObject::IsShown ( ) const
inline

Returns whether game object is currently shown.

Only shown objects are rendered and have their Render function triggered.

See also
IGameObject::Show, IGameObject::Render
Returns
true if the object is shown, false otherwise.

◆ Load()

virtual LoadState JadeEngine::IGameObject::Load ( SDL_Renderer *  renderer)
inlinevirtual

Triggered every frame when GetLoadState function returns kLoadState_Wanted to allow resources, such as textures, to be loaded.

The trigger order is the following: IScene::PreUpdate -> IGameObject::Load -> IGameObject::Update -> IScene::Update -> IGameObject::Load -> IGameObject::Render.

Parameters
rendererThe engine's SDL2 renderer that can be used to create resources.
Returns
The function must return the load state that reflects the result of the load operation. It will be used in SetLoadState function by the Game class.
See also
GetLoadState

Reimplemented in JadeEngine::TextSprite, JadeEngine::TextBox, and JadeEngine::Text.

◆ Render()

virtual void JadeEngine::IGameObject::Render ( SDL_Renderer *  renderer)
inlinevirtual

Triggered every frame while the scene that owns this game object is active, the game object was successfully loaded and the game object is shown.

The trigger order is the following: IScene::PreUpdate -> IGameObject::Load -> IGameObject::Update -> IScene::Update -> IGameObject::Load -> IGameObject::Render.

Parameters
rendererThe engine's SDL2 renderer that should be used to render the game object.
See also
IGameObject::Update, LoadState, IGameObject::IsShown

Reimplemented in JadeEngine::Sprite, JadeEngine::LineStrip, JadeEngine::TextSprite, JadeEngine::TextBox, JadeEngine::Text, and JadeEngine::BoxSprite.

◆ SetLoadState()

void JadeEngine::IGameObject::SetLoadState ( const LoadState  newState)
inline

Set the load state to a new value.

See also
LoadState

◆ Show()

virtual void JadeEngine::IGameObject::Show ( const bool  show)
inlinevirtual

Show or hide game object.

Warning
This does not affect any owned child game objects as this interface has no knowledge of them. It only handles tracking the visibility state. It is recommended to override this function for game object that own other game objects. Inside the overridden function one should call this - base - function and handle hiding/showing of children game objects there.
void SomeGameObject::Show(const bool shown) //override
{
// Show or hide any child objects or perform any other necessary operations
_childObject->Show(IsShown());
}
See also
IGameObject::IsShown

Reimplemented in JadeEngine::Button, JadeEngine::Dropdown, JadeEngine::ProgressBar, JadeEngine::Slider, JadeEngine::Tooltip, JadeEngine::LineGrid, JadeEngine::Checkbox, JadeEngine::LineBox, and JadeEngine::FTC.

◆ Update()

virtual void JadeEngine::IGameObject::Update ( )
inlinevirtual

Triggered every frame while the scene that owns this game object is active and the game object was successfully loaded.

The trigger order is the following: IScene::PreUpdate -> IGameObject::Load -> IGameObject::Update -> IScene::Update -> IGameObject::Load -> IGameObject::Render.

To obtain delta time since last frame use GTime.deltaTime.

See also
Time, LoadState, IGameObject::Render, IScene::Update, IScene::PreUpdate

Reimplemented in JadeEngine::Button, JadeEngine::LineStrip, JadeEngine::ProgressBar, JadeEngine::Dropdown, JadeEngine::Slider, JadeEngine::Tooltip, JadeEngine::LineGrid, JadeEngine::Checkbox, and JadeEngine::LineBox.

Member Data Documentation

◆ transform

const std::shared_ptr<Transform> JadeEngine::IGameObject::transform

Transform of the game object.

See also
Transform

The documentation for this class was generated from the following file:
JadeEngine::IGameObject::Show
virtual void Show(const bool show)
Definition: IGameObject.h:170
JadeEngine::IGameObject::IsShown
bool IsShown() const
Definition: IGameObject.h:153
JadeEngine::IGameObject
Definition: IGameObject.h:78
JadeEngine::IGameObject::Update
virtual void Update()
Definition: IGameObject.h:101
JadeEngine::Sprite
Definition: Sprite.h:90