SAGE
A Simple Academic Game Engine
Loading...
Searching...
No Matches
Sage::CSprite Class Reference

The sprite. More...

#include <SageSprite.h>

Inheritance diagram for Sage::CSprite:
Collaboration diagram for Sage::CSprite:

Public Member Functions

 CSprite (size_t)
 Constructor.
 
 CSprite (size_t, RECT *)
 Constructor.
 
 ~CSprite ()
 Destructor.
 
CTextureDescGetTextureDesc (const size_t=0)
 Get texture descriptor.
 
CTextureDescGetTextureDescPtr ()
 Get texture descriptor array.
 
void SetTextureDescPtr (CTextureDesc *)
 Set texture descriptor array.
 
bool GetRect (RECT &, const size_t=0) const
 Get bounding rectangle in sprite sheet.
 
const float GetWidth (const UINT=0) const
 Get sprite width.
 
const float GetHeight (const UINT=0) const
 Get sprite height.
 
void GetSize (const UINT, float &, float &) const
 Get sprite width and height.
 
void GetExtents (const UINT, XMUINT2 &) const
 Get extents of sprite or sprite sheet/.
 
const size_t GetNumFrames () const
 Get number of frames.
 

Private Attributes

CTextureDescm_pTextureDesc = nullptr
 Texture descriptor array for frames.
 
RECT * m_pRect = nullptr
 Bounding rectangle in sprite sheet.
 
size_t m_nNumFrames = 1
 Number of animation frames.
 

Additional Inherited Members

- Static Protected Attributes inherited from Sage::CComponent
static std::unique_ptr< CTimerm_pTimer = std::make_unique<CTimer>()
 Pointer to a timer.
 
static std::unique_ptr< CRandomm_pRandom = std::make_unique<CRandom>()
 Pointer to a PRNG.
 
static std::unique_ptr< CSoundm_pSound = std::make_unique<CSound>()
 Pointer to sound manager.
 
static std::unique_ptr< CKeyboardm_pKeyboard
 Pointer to a keyboard handler.
 
static std::unique_ptr< CMousem_pMouse = std::make_unique<CMouse>()
 Pointer to a mouse handler.
 
static std::unique_ptr< CControllerm_pController
 Pointer to a controller.
 

Detailed Description

A sprite consists of textures for its animation frames and the associated texture information.

Constructor & Destructor Documentation

◆ CSprite() [1/2]

CSprite::CSprite ( size_t n)

Create the texture descriptor array.

Parameters
nNumber of animation frames.

◆ CSprite() [2/2]

CSprite::CSprite ( size_t n,
RECT * pRect )

Create a sprite from bounding rectangles in a sprite sheet.

Parameters
nNumber of animation frames.
pRectBounding rectangle array.

◆ ~CSprite()

CSprite::~CSprite ( )

Clean up the texture descriptor array and the bounding rectangle array. If the bounding rectangle array is empty, then this sprite comes from its own image file, so we need to delete the texture descriptor array. Otherwise, it is from a sprite sheet in which case it shares its texture with the sprite sheet and all of the other sprites within it, so we do not delete the descriptor array (the sprite sheet will take care of that).

Member Function Documentation

◆ GetExtents()

void CSprite::GetExtents ( const UINT n,
XMUINT2 & x ) const

Get the extents of a sprite. If the sprite is a single file, then this will be the sprite width and height. If the sprite is from a sprite sheet. then this will be the width and height of the sprite sheet, not the bounding rectangle of the sprite.

Parameters
n[in] Frame number, assumed to be in range.
x[out] Sprite extents.
Here is the caller graph for this function:

◆ GetHeight()

const float CSprite::GetHeight ( const UINT n = 0) const

Reader function for the height of a frame.

Parameters
nFrame number, assumed to be in range, defaults to zero.
Returns
Height of frame in pixels.
Here is the caller graph for this function:

◆ GetNumFrames()

const size_t CSprite::GetNumFrames ( ) const

Reader function for the number of animation frames.

Returns
Number of animation frames.
Here is the caller graph for this function:

◆ GetRect()

bool CSprite::GetRect ( RECT & r,
const size_t i = 0 ) const

Get sprite bounding rectangle in sprite sheet. Note that the rectangle can be modified using the reference returned by this function.

Parameters
r[out] Reference to bounding rectangle from frame.
iFrame number, defaults to zero.
Returns
true if bounding rectangle exists, false otherwise.
Here is the caller graph for this function:

◆ GetSize()

void CSprite::GetSize ( const UINT n,
float & x,
float & y ) const

Reader function for the width and height of a frame.

Parameters
n[in] Frame number, assumed to be in range.
x[out] Width of frame in pixels.
y[out] Height of frame in pixels.
Here is the caller graph for this function:

◆ GetTextureDesc()

CTextureDesc & CSprite::GetTextureDesc ( const size_t i = 0)

Reference function for the texture descriptor for an animation frame. Note that the texture descriptor can be modified using the reference returned by this function.

Parameters
iFrame number, defaults to zero.
Returns
Reference to the texture descriptor for frame i.
Here is the caller graph for this function:

◆ GetTextureDescPtr()

CTextureDesc * CSprite::GetTextureDescPtr ( )

Reader function for the texture descriptor array.

Returns
Pointer to the start of the texture descriptor array.

◆ GetWidth()

const float CSprite::GetWidth ( const UINT n = 0) const

Reader function for the width of a frame.

Parameters
nFrame number, assumed to be in range, defaults to zero.
Returns
Width of frame in pixels.
Here is the caller graph for this function:

◆ SetTextureDescPtr()

void CSprite::SetTextureDescPtr ( CTextureDesc * p)

Writer function for the texture descriptor array.

Parameters
pPointer to the start of the texture descriptor array.
Here is the caller graph for this function: