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

#include <tb_sprite.h>

Inheritance diagram for TurtleBrains::Graphics::Sprite:
TurtleBrains::Graphics::Graphic TurtleBrains::Graphics::AnimatedSprite

Public Member Functions

 Sprite (const SpriteFrame &spriteFrame)
 
 Sprite (const tbCore::tbString &textureFile, const PixelSpace &frameX=0, const PixelSpace &frameY=0, const PixelSpace &frameWidth=0, const PixelSpace &frameHeight=0)
 
 Sprite (const TextureHandle &textureHandle, const PixelSpace &frameX=0, const PixelSpace &frameY=0, const PixelSpace &frameWidth=0, const PixelSpace &frameHeight=0)
 
 Sprite (const tbCore::tbString &spriteSheet, const tbCore::tbString &spriteName)
 
 Sprite (const Sprite &other)
 
virtual ~Sprite (void)
 
Spriteoperator= (const Sprite &other)
 
virtual PixelSpace GetPixelWidth (void) const override
 
virtual PixelSpace GetPixelHeight (void) const override
 
- Public Member Functions inherited from TurtleBrains::Graphics::Graphic
 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)
 
void SetOrigin (const AnchorLocation &anchor)
 
void SetOrigin (const float originX, const float originY)
 
float GetDepth (void) const
 
void SetDepth (const float newDepth)
 
void SetScale (const float scale)
 
void SetScale (const float scaleX, const float scaleY)
 
void SetRotation (const float rotation)
 
float GetRotation (void) const
 
void SetScroll (const float scroll)
 
void SetScroll (const float scrollX, const float scrollY)
 
bool IsRelative (void) const
 
virtual void SetColor (const tbGraphics::Color &newColor)
 
float GetWidth (void) const
 
float GetHeight (void) const
 

Protected Member Functions

virtual void OnRender (void) const override
 
void SetSpriteFrame (const SpriteFrame &spriteFrame)
 
const SpriteFrameGetSpriteFrame (void) const
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Graphic
virtual void OnUpdate (const float deltaTime)
 
const ColorGetColor (void) const
 
virtual void ApplyTransform (void) const
 
virtual void PopTransform (void) const
 

Detailed Description

The Sprite is likely the most common Graphic object used when creating a two-dimensional game. The Sprite contains a little information about the Texture and a rectangle on that texture that describes what should be rendered by the Sprite.

Constructor & Destructor Documentation

TurtleBrains::Graphics::Sprite::Sprite ( const SpriteFrame spriteFrame)
explicit

Constructs a Sprite object with the given SpriteFrame which contains the texture and location size of the sprite.

TurtleBrains::Graphics::Sprite::Sprite ( const tbCore::tbString textureFile,
const PixelSpace frameX = 0,
const PixelSpace frameY = 0,
const PixelSpace frameWidth = 0,
const PixelSpace frameHeight = 0 
)
explicit

Construct a sprite from a filepath of a texture with a given frame location and size.

Parameters
textureFileThe filepath of a texture to load into the texture manager, if it isn't already, and use as the texture for the sprites frame.
frameXThe location of the left edge of the sprites frame in pixels from the left edge of the texture.
frameYThe location of the top edge of the sprites frame in pixels from the top edge of the texture.
frameWidthThe width of the sprite frame in pixels, frameWidth + frameX must not exceed texture width, or an error condition will be triggered.
frameHeightThe height of the sprite frame in pixels, frameHeight + frameY must not exceed texture height, or an error condition will be triggered.
TurtleBrains::Graphics::Sprite::Sprite ( const TextureHandle textureHandle,
const PixelSpace frameX = 0,
const PixelSpace frameY = 0,
const PixelSpace frameWidth = 0,
const PixelSpace frameHeight = 0 
)
explicit

Construct a sprite from a handle of an already loaded texture given a frame location and size.

Parameters
textureHandleThe handle of the loaded texture, cannot be kInvalidTexture or an error condition will be triggered.
frameXThe location of the left edge of the sprites frame in pixels from the left edge of the texture.
frameYThe location of the top edge of the sprites frame in pixels from the top edge of the texture.
frameWidthThe width of the sprite frame in pixels, frameWidth + frameX must not exceed texture width, or an error condition will be triggered.
frameHeightThe height of the sprite frame in pixels, frameHeight + frameY must not exceed texture height, or an error condition will be triggered.
TurtleBrains::Graphics::Sprite::Sprite ( const tbCore::tbString spriteSheet,
const tbCore::tbString spriteName 
)

Creates an Sprite similar to Sprite(tbGraphics::theSpriteManager.GetSprite("sheet", "sprite")) except more convenient.

Parameters
spriteSheetNameA name to a SpriteSheet that was loaded during a call to SpriteManager::LoadSpriteSheetFromFile() or SpriteManager::LoadSpriteSheetFromData(). If no SpriteSheet is found with the provided spriteSheetName, an error condition will be triggered.
spriteNameA name to the sprite data on the specified SpriteSheet which was loaded. If no sprite data is found with the provided spriteName and error condition will be triggered.
TurtleBrains::Graphics::Sprite::Sprite ( const Sprite other)

Construct a sprite from another spriute, copying the sprites frame, color, scaling and other properties.

Parameters
otherThe sprite to copy and mimic.
virtual TurtleBrains::Graphics::Sprite::~Sprite ( void  )
virtual

Destroys a sprite object, which doesn't do any heavy lifting at this time.

Member Function Documentation

virtual PixelSpace TurtleBrains::Graphics::Sprite::GetPixelHeight ( void  ) const
overridevirtual

Returns the height of the sprite in pixels.

Reimplemented from TurtleBrains::Graphics::Graphic.

virtual PixelSpace TurtleBrains::Graphics::Sprite::GetPixelWidth ( void  ) const
overridevirtual

Returns the width of the sprite in pixels.

Reimplemented from TurtleBrains::Graphics::Graphic.

const SpriteFrame& TurtleBrains::Graphics::Sprite::GetSpriteFrame ( void  ) const
protected

Returns the current sprite frame to be inspected or used by subclasses.

virtual void TurtleBrains::Graphics::Sprite::OnRender ( void  ) const
overrideprotectedvirtual

Actually performs the rendering of the sprite to the screen with OpenGL.

Note
OnRender() should not be called directly, you should call Render() which will first check if the Graphic is visible before rendering.

Implements TurtleBrains::Graphics::Graphic.

Sprite& TurtleBrains::Graphics::Sprite::operator= ( const Sprite other)

Set a sprite object to be the show the same sprite frame, color, scaling, origin and all other properties copied from the other sprite.

Parameters
otherThe sprite to copy and mimic.
void TurtleBrains::Graphics::Sprite::SetSpriteFrame ( const SpriteFrame spriteFrame)
protected

Changes the frame of the Sprite so it can flip to a new frame for AnimatedSprite or other effects from subclasses.

Note
The sprite frame textureHandle MUST match the current sprite frame texture handle or an error condition will be triggered.