![]() |
The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
|
The sprite. More...
#include <Sprite.h>
Public Member Functions | |
LSprite (size_t) | |
Constructor. More... | |
LSprite (size_t, RECT *) | |
Constructor. More... | |
~LSprite () | |
Destructor. More... | |
LTextureDesc & | GetTextureDesc (const size_t=0) |
Get texture descriptor. More... | |
LTextureDesc * | GetTextureDescPtr () |
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 | |
LTextureDesc * | m_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 LTimer * | m_pTimer = &cTimer |
Pointer to a timer. More... | |
static LRandom * | m_pRandom = &cRandom |
Pointer to a PRNG. More... | |
static LKeyboard * | m_pKeyboard = &cKeyboard |
Pointer to a keyboard handler. More... | |
static LXBoxController * | m_pController = &cController |
Pointer to a XBox controller. More... | |
static LSound * | m_pAudio = &cAudio |
Pointer to an audio player. More... | |
A sprite consists of textures for its animation frames and the associated texture information.
LSprite::LSprite | ( | size_t | n | ) |
Create the texture descriptor array.
n | Number of animation frames. |
LSprite::LSprite | ( | size_t | n, |
RECT * | pRect | ||
) |
Create a sprite from bounding rectangles in a sprite sheet.
n | Number of animation frames. |
pRect | Bounding rectangle array. |
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).
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.
n | [in] Frame number, assumed to be in range. |
x | [out] Sprite extents. |
const float LSprite::GetHeight | ( | const UINT | n = 0 | ) | const |
Reader function for the height of a frame.
n | Frame number, assumed to be in range, defaults to zero. |
const size_t LSprite::GetNumFrames | ( | ) | const |
Reader function for the number of animation frames.
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.
r | [out] Reference to bounding rectangle from frame. |
i | Frame number, defaults to zero. |
void LSprite::GetSize | ( | const UINT | n, |
float & | x, | ||
float & | y | ||
) | const |
Reader function for the width and height of a frame.
n | [in] Frame number, assumed to be in range. |
x | [out] Width of frame in pixels. |
y | [out] Height of frame in pixels. |
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.
i | Frame number, defaults to zero. |
LTextureDesc * LSprite::GetTextureDescPtr | ( | ) |
Reader function for the texture descriptor array.
const float LSprite::GetWidth | ( | const UINT | n = 0 | ) | const |
Reader function for the width of a frame.
n | Frame number, assumed to be in range, defaults to zero. |
void LSprite::SetTextureDescPtr | ( | LTextureDesc * | p | ) |
Writer function for the texture descriptor array.
p | Pointer to the start of the texture descriptor array. |