The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
Public Member Functions | Private Attributes | List of all members
LSprite Class Reference

The sprite. More...

#include <Sprite.h>

Inheritance diagram for LSprite:
LComponent

Public Member Functions

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

Private Attributes

LTextureDescm_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 LComponent
static LTimerm_pTimer = &cTimer
 Pointer to a timer. More...
 
static LRandomm_pRandom = &cRandom
 Pointer to a PRNG. More...
 
static LKeyboardm_pKeyboard = &cKeyboard
 Pointer to a keyboard handler. More...
 
static LXBoxControllerm_pController = &cController
 Pointer to a XBox controller. More...
 
static LSoundm_pAudio = &cAudio
 Pointer to an audio player. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ LSprite() [1/2]

LSprite::LSprite ( size_t  n)

Create the texture descriptor array.

Parameters
nNumber of animation frames.

◆ LSprite() [2/2]

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

Create a sprite from bounding rectangles in a sprite sheet.

Parameters
nNumber of animation frames.
pRectBounding rectangle array.

◆ ~LSprite()

LSprite::~LSprite ( )

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 LSprite::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.

◆ GetHeight()

const float LSprite::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.

◆ GetNumFrames()

const size_t LSprite::GetNumFrames ( ) const

Reader function for the number of animation frames.

Returns
Number of animation frames.

◆ GetRect()

bool LSprite::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.

◆ GetSize()

void LSprite::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.

◆ GetTextureDesc()

LTextureDesc & LSprite::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.

◆ GetTextureDescPtr()

LTextureDesc * LSprite::GetTextureDescPtr ( )

Reader function for the texture descriptor array.

Returns
Pointer to the start of the texture descriptor array.

◆ GetWidth()

const float LSprite::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.

◆ SetTextureDescPtr()

void LSprite::SetTextureDescPtr ( LTextureDesc p)

Writer function for the texture descriptor array.

Parameters
pPointer to the start of the texture descriptor array.