#include <tb_graphic.h>
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::Vector2 & | GetPosition (void) const |
void | SetPosition (const float x, const float y) |
void | SetPosition (const tbMath::Vector2 &position) |
void | SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero()) |
void | SetOrigin (const float originX, const float originY) |
void | SetOrigin (const tbMath::Vector2 &origin) |
float | GetDepth (void) const |
void | SetDepth (const float newDepth) |
const tbMath::Vector2 & | GetScale (void) const |
void | SetScale (const float scale) |
void | SetScale (const float scaleX, const float scaleY) |
float | GetRotation (void) const |
void | SetRotation (const float rotation) |
void | SetScroll (const float scroll) |
void | SetScroll (const float scrollX, const float scrollY) |
bool | IsRelative (void) const |
const Color & | GetColor (void) const |
virtual void | SetColor (const tbGraphics::Color &newColor) |
virtual PixelSpace | GetPixelWidth (void) const |
virtual PixelSpace | GetPixelHeight (void) const |
float | GetWidth (void) const |
float | GetHeight (void) const |
Protected Member Functions | |
virtual void | OnUpdate (const float deltaTime) |
virtual void | OnRender (void) const =0 |
virtual void | ApplyTransform (void) const |
virtual void | PopTransform (void) const |
The Graphic is an abstract interface for Text, Sprite and other graphical objects that can be updated and displayed.
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 | ) |
|
virtual |
Destroys the Graphic object by doing nothing since no resources need to be cleaned up.
|
protectedvirtual |
Applies the objects scaling, rotation, camera and translation transform before it gets rendered. This is automatically called in Render() before OnRender() gets called if the object is visible.
const Color& TurtleBrains::Graphics::Graphic::GetColor | ( | void | ) | const |
Returns the color of the Graphic which defaults to White (0xFFFFFFFF) but can be changed with SetColor().
float TurtleBrains::Graphics::Graphic::GetDepth | ( | void | ) | const |
Returns the depth, Z value, of the Graphic object.
|
inline |
This is really the height of the graphic object in PixelSpace converted to a floating point for convenience.
|
inlinevirtual |
This should be overridden to return the height of the graphic in PixelSpace units to be used in placement and anchor point computations.
Reimplemented in TurtleBrains::Graphics::Sprite, TurtleBrains::Graphics::Text, and TurtleBrains::Graphics::PolygonShape.
|
inlinevirtual |
This should be overridden to return the width of the graphic in PixelSpace units to be used in placement and anchor point computations.
Reimplemented in TurtleBrains::Graphics::Sprite, TurtleBrains::Graphics::Text, and TurtleBrains::Graphics::PolygonShape.
const tbMath::Vector2& TurtleBrains::Graphics::Graphic::GetPosition | ( | void | ) | const |
Returns the position of the sprite as a Vector2 object.
|
inline |
Returns the current rotation/orientation of the sprite.
|
inline |
This is really the width of the graphic object in PixelSpace converted to a floating point for convenience.
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.
|
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().
Implemented in TurtleBrains::Game::Entity, TurtleBrains::Game::TileSystem, TurtleBrains::Graphics::Sprite, TurtleBrains::Graphics::OutlinedPolygonShape, TurtleBrains::Graphics::Text, TurtleBrains::Game::GameScene, TurtleBrainsExpress::Counters::HealthIcons, TurtleBrains::Graphics::GraphicList, TurtleBrainsExpress::Graphics::ParallaxBackdrop, TurtleBrains::Graphics::PolygonShape, TurtleBrains::Graphics::LineContainer, and TurtleBrainsExpress::Counters::HealthBar.
|
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().
Reimplemented in TurtleBrains::Game::Entity, TurtleBrains::Graphics::AnimatedSprite, TurtleBrains::Game::EntityManager, TurtleBrainsExpress::Counters::Counter, TurtleBrains::Game::GameScene, TurtleBrainsExpress::Counters::HealthIcons, TurtleBrains::Graphics::GraphicList, and TurtleBrainsExpress::Counters::HealthBar.
|
protectedvirtual |
Removes all transformations that were applied during ApplyTransform as if nothing even happened. This is automatically called in Render() after OnRender() was called if the object is visible.
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 |
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, TurtleBrains::Graphics::PolygonShape, and TurtleBrains::Graphics::LineContainer.
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.
newDepth | The depth of the Graphic object, smaller being farther away and larger being closer to the camera. |
void TurtleBrains::Graphics::Graphic::SetOrigin | ( | const AnchorLocation & | anchor, |
const tbMath::Vector2 & | offset = tbMath::Vector2::Zero() |
||
) |
Sets the origin or hot-spot of the sprite. This is an offset where the sprite will be positioned by and rotated around. The AnchorLocation will describe where the origin offset with a 9 locations, the four corners, and center points of each edge.
|
inline |
Sets the origin or a hot-spot of the sprite. This is an offset where the sprite will be positioned by and rotated around.
|
inline |
Sets the origin or a hot-spot of the sprite. This is an offset where the sprite will be positioned by and rotated around.
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.
x | The 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. |
y | The 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.
position | Where 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. |
|
inline |
Set the rotation/orientation of the sprite so it can rotate around the game world and animate things such as windmills, tires, etc.
rotation | The angle in degrees of the sprite, positive values rotate clockwise. |
|
inline |
Changes the scaling of the sprite uniformly on each axis.
scale | The amount of scaling to apply, 1.0 is normal scale, 0.5 is half size and 2.0 is double. |
|
inline |
Changes the scaling of the sprite on each axis separately.
scaleX | The amount of scaling to apply on the X-axis, 1.0 is normal scale, 0.5 is half size. |
scaleY | The amount of scaling to apply on the Y-axis, 1.0 is normal scale, 2.0 is double size. |
|
inline |
This value changes how the graphic interacts with the camera, a scroll value of 0 will attach the graphic to the camera which can be useful for UI graphic objects. A scroll value of 1 will scroll at a normal rate as the camera moves around while other values can create a parallax effect.
|
inline |
This value changes how the graphic interacts with the camera, a scroll value of 0 will attach the graphic to the camera which can be useful for UI graphic objects. A scroll value of 1 will scroll at a normal rate as the camera moves around while other values can create a parallax effect.
scrollX | The scroll value for horizontal movement/interaction with the camera. |
scrollY | The scroll value for vertical movement/interaction with the camera. |
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.