Building Game Engines
Sprite Class Reference

Sprite supports detecting the current orientation and set moving direction functions for characters. More...

#include <Sprite.hpp>

Inheritance diagram for Sprite:
Inheritance graph
Collaboration diagram for Sprite:
Collaboration graph

Public Member Functions

 Sprite ()
 
 Sprite (const char *const imgFilePath, SDL_Renderer *renderer, const int spriteInfo[SPRITE_INFO_NUM])
 
 ~Sprite ()
 
void Update (int posX, int posY)
 
void Update (int srcX, int srcY, int srcW, int srcH, int destX, int destY, int destW, int destH)
 
void Render (SDL_Renderer *ren)
 Render something to the active viewport. More...
 
void SetMovingDir (PLAYER_DIR isMovingRight)
 Set the moving direction of this sprite. More...
 
bool IsFacingRight ()
 Judge the current orientation is right. -false left -true right. More...
 
void ResetFrame ()
 
void LoadImage (std::string filePath, SDL_Renderer *ren, const int spriteInfo[SPRITE_INFO_NUM])
 
void Render (int posX, int posY, int frameX, int frameY, SDL_Renderer *ren, bool flip)
 Render the sprite with specific info. More...
 
void Render (SDL_Renderer *ren, SDL_RendererFlip flip)
 Render the sprite with flip info. More...
 
bool PlayedOnce ()
 checks if the current animation has been played through More...
 
void SetPos (int x, int y)
 set the play position More...
 
- Public Member Functions inherited from Component
 Component ()
 
 ~Component ()
 

Detailed Description

Sprite supports detecting the current orientation and set moving direction functions for characters.

Constructor & Destructor Documentation

◆ Sprite() [1/2]

Sprite::Sprite ( )

Constructor

◆ Sprite() [2/2]

Sprite::Sprite ( const char *const  imgFilePath,
SDL_Renderer *  renderer,
const int  spriteInfo[SPRITE_INFO_NUM] 
)

Constructor

Parameters
imgFilePathThe file name of the source image file.
rendererReference to SDL_Renderer.
spriteInfoStores width and height of the sprite in the source file and in the game window.

◆ ~Sprite()

Sprite::~Sprite ( )

Destructor

Member Function Documentation

◆ IsFacingRight()

bool Sprite::IsFacingRight ( )

Judge the current orientation is right. -false left -true right.

◆ LoadImage()

void Sprite::LoadImage ( std::string  filePath,
SDL_Renderer *  ren,
const int  spriteInfo[SPRITE_INFO_NUM] 
)

Load image file and change the sprite sheet.

Parameters
filePathThe file name of the image file.
renReference to SDL renderer.
spriteInfoStores width and height of the sprite in the source file and in the game window.

◆ PlayedOnce()

bool Sprite::PlayedOnce ( )

checks if the current animation has been played through

◆ Render() [1/3]

void Sprite::Render ( int  posX,
int  posY,
int  frameX,
int  frameY,
SDL_Renderer *  ren,
bool  flip 
)

Render the sprite with specific info.

◆ Render() [2/3]

void Sprite::Render ( SDL_Renderer *  ren)

Render something to the active viewport.

Parameters
renReference to SDL renderer.

◆ Render() [3/3]

void Sprite::Render ( SDL_Renderer *  ren,
SDL_RendererFlip  flip 
)

Render the sprite with flip info.

◆ ResetFrame()

void Sprite::ResetFrame ( )

Set the frame this sprite's animation to 0;

◆ SetMovingDir()

void Sprite::SetMovingDir ( PLAYER_DIR  isMovingRight)

Set the moving direction of this sprite.

◆ SetPos()

void Sprite::SetPos ( int  x,
int  y 
)

set the play position

◆ Update() [1/2]

void Sprite::Update ( int  posX,
int  posY 
)

Update the position of this sprite.

Parameters
posXThe x location of the sprite's upper left corner in game.
posYThe y location of the sprite's upper left corner in game.

◆ Update() [2/2]

void Sprite::Update ( int  srcX,
int  srcY,
int  srcW,
int  srcH,
int  destX,
int  destY,
int  destW,
int  destH 
)

Update the position of this sprite.

Parameters
srcXThe x location of the sprite's upper left corner in the texture.
srcYThe y location of the sprite's upper left corner in the texture.
srcWThe width of the sprite in the texture.
srcHThe width of the sprite in the texture.
destXThe x location of the sprite's upper left corner in game.
destYThe y location of the sprite's upper left corner in game.
destWThe width of the sprite in the game.
destHThe width of the sprite in the game.