Sprite supports detecting the current orientation and set moving direction functions for characters.
More...
#include <Sprite.hpp>
|
| 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...
|
|
| Component () |
|
| ~Component () |
|
Sprite supports detecting the current orientation and set moving direction functions for characters.
◆ Sprite() [1/2]
◆ Sprite() [2/2]
Sprite::Sprite |
( |
const char *const |
imgFilePath, |
|
|
SDL_Renderer * |
renderer, |
|
|
const int |
spriteInfo[SPRITE_INFO_NUM] |
|
) |
| |
Constructor
- Parameters
-
imgFilePath | The file name of the source image file. |
renderer | Reference to SDL_Renderer. |
spriteInfo | Stores width and height of the sprite in the source file and in the game window. |
◆ ~Sprite()
◆ 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
-
filePath | The file name of the image file. |
ren | Reference to SDL renderer. |
spriteInfo | Stores 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
-
ren | Reference 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 |
|
) |
| |
◆ Update() [1/2]
void Sprite::Update |
( |
int |
posX, |
|
|
int |
posY |
|
) |
| |
Update the position of this sprite.
- Parameters
-
posX | The x location of the sprite's upper left corner in game. |
posY | The 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
-
srcX | The x location of the sprite's upper left corner in the texture. |
srcY | The y location of the sprite's upper left corner in the texture. |
srcW | The width of the sprite in the texture. |
srcH | The width of the sprite in the texture. |
destX | The x location of the sprite's upper left corner in game. |
destY | The y location of the sprite's upper left corner in game. |
destW | The width of the sprite in the game. |
destH | The width of the sprite in the game. |