TurtleBrains  0.2.1
High quality, portable, C++ API for native application and game development.
TurtleBrains::Graphics::Graphic Class Referenceabstract

#include <tb_graphic.h>

Inheritance diagram for TurtleBrains::Graphics::Graphic:
TurtleBrains::Graphics::GraphicList TurtleBrains::Graphics::Sprite TurtleBrains::Graphics::Text TurtleBrains::Game::Entity TurtleBrains::Game::EntityManager TurtleBrains::Game::TileSystem TurtleBrains::Graphics::AnimatedSprite TurtleBrains::Game::GameScene

Public Member Functions

 Graphic (void)
 
 Graphic (const Graphic &other)
 
virtual ~Graphic (void)
 
bool IsActive (void) const
 
void SetActive (const bool isActive)
 
void Update (const float deltaTime)
 
bool IsVisible (void) const
 
void SetVisible (const bool isVisible)
 
void Render (void) const
 
const tbMath::Vector2GetPosition (void) const
 
void SetPosition (const float x, const float y)
 
void SetPosition (const tbMath::Vector2 &position)
 
float GetDepth (void) const
 
void SetDepth (const float newDepth)
 
bool IsRelative (void) const
 
virtual void SetColor (const tbGraphics::Color &newColor)
 

Protected Member Functions

virtual void OnUpdate (const float deltaTime)
 
virtual void OnRender (void) const =0
 
const ColorGetColor (void) const
 

Detailed Description

The Graphic is an abstract interface for Text, Sprite and other graphical objects that can be updated and displayed.

Constructor & Destructor Documentation

TurtleBrains::Graphics::Graphic::Graphic ( void  )

Constructs a Graphic object that starts out active and visible with a position of (0.0f, 0.0f) and depth at 0.0f.

TurtleBrains::Graphics::Graphic::Graphic ( const Graphic other)

Constructs a Graphic object by copying the details from the other Graphic object.

Parameters
otherThe Graphic object to copy and mimic.
virtual TurtleBrains::Graphics::Graphic::~Graphic ( void  )
virtual

Destroys the Graphic object by doing nothing since no resources need to be cleaned up.

Member Function Documentation

const Color& TurtleBrains::Graphics::Graphic::GetColor ( void  ) const
protected

Returns the color of the Graphic which defaults to Color::kWhite but can be changed with SetColor().

float TurtleBrains::Graphics::Graphic::GetDepth ( void  ) const

Returns the depth, Z value, of the Graphic object.

const tbMath::Vector2& TurtleBrains::Graphics::Graphic::GetPosition ( void  ) const

Returns the position of the sprite as a Vector2 object.

bool TurtleBrains::Graphics::Graphic::IsActive ( void  ) const

Returns true if the Graphic is currently active and needing to be updated, or false if the OnUpdate() calls should be skipped.

bool TurtleBrains::Graphics::Graphic::IsRelative ( void  ) const

This will return true if the Graphic object is relative to it's parent object, such as the contained GraphicList. Currently all Graphics are always relative, although this may be updated in future versions of TurtleBrains.

bool TurtleBrains::Graphics::Graphic::IsVisible ( void  ) const

Returns true if the Graphic is currently visible and needing to be displayed, or false if the OnRender() calls should be skipped.

virtual void TurtleBrains::Graphics::Graphic::OnRender ( void  ) const
protectedpure virtual

This must be overridden by a subclass to actually display the Graphic on the screen. The function will be invoked when Render() is called and the object IsVisible().

Note
OnRender() should not be called directly, even from a subclass. Use Render() which will first check if the Graphic IsVisible() before displaying with OnRender().

Implemented in TurtleBrains::Graphics::Sprite, TurtleBrains::Game::Entity, TurtleBrains::Game::TileSystem, TurtleBrains::Graphics::Text, TurtleBrains::Game::GameScene, and TurtleBrains::Graphics::GraphicList.

virtual void TurtleBrains::Graphics::Graphic::OnUpdate ( const float  deltaTime)
protectedvirtual

This should be overridden by a subclass if it needs to perform any updates per frame before displaying / rendering a new frame. This function will be invoked when Update() is called and the object IsActive().

Note
OnUpdate() should not be called directly, even from a subclass. Use Update() which will first check if the Graphic IsActive() before updating with OnUpdate().

Reimplemented in TurtleBrains::Graphics::AnimatedSprite, TurtleBrains::Game::Entity, TurtleBrains::Game::EntityManager, TurtleBrains::Game::GameScene, and TurtleBrains::Graphics::GraphicList.

void TurtleBrains::Graphics::Graphic::Render ( void  ) const

First checks to see if the object IsVisible() and calls OnRender() if it is. If the object is not visible nothing happens.

void TurtleBrains::Graphics::Graphic::SetActive ( const bool  isActive)

Sets a flag that when false causes the Graphic to skip the OnUpdate() calls and when true will proceed with the OnUpdate() calls. Defaults to true, may lead to better performance if false when the object does not need to be updated.

virtual void TurtleBrains::Graphics::Graphic::SetColor ( const tbGraphics::Color newColor)
virtual

Change the color of the sprite so it can fade in/out with alpha, or modify the color for other effects.

Reimplemented in TurtleBrains::Graphics::GraphicList.

void TurtleBrains::Graphics::Graphic::SetDepth ( const float  newDepth)

Sets the depth of the graphic object which should be within a range of -1.0f for objects far in the background and 1.0f for the objects nearest to the camera. The default value is 0.0f.

Parameters
newDepthThe depth of the Graphic object, smaller being farther away and larger being closer to the camera.
void TurtleBrains::Graphics::Graphic::SetPosition ( const float  x,
const float  y 
)

Sets the position of the object to the x and y location in world space.

Parameters
xThe position in the world along the worlds X-axis. 0 being the origin, by default the world X-axis is horizontal with 0 being the left edge of the screen and positive numbers toward the right.
yThe position in the world along the worlds Y-axis. 0 being the origin, by default the world Y-axis is vertical with 0 being the top edge of the screen and positive numbers toward the bottom.
void TurtleBrains::Graphics::Graphic::SetPosition ( const tbMath::Vector2 position)

Sets the position of the object to the location in world space with the given x and y components of the Vector2.

Parameters
positionWhere in the world along the each axis the Graphic should be placed. By default the world X-axis is horizontal with 0 being the left edge of the screen and positive numbers toward the right and the Y-axis is vertical with 0 being the top edge of the screen and positive numbers toward the bottom.
void TurtleBrains::Graphics::Graphic::SetVisible ( const bool  isVisible)

Sets a flag that when false causes the Graphic to skip the OnRender() calls and when true will proceed with the OnRender() calls. Defaults to true, may lead to better performance if false when the object does not need to be displayed.

void TurtleBrains::Graphics::Graphic::Update ( const float  deltaTime)

First checks to see if the object IsActive() and calls OnUpdate() if it is. If the object is not active nothing happens.