AnimatedSprite - ZenXChaos/MapleStorySDLCPP GitHub Wiki

Game

AnimatedSprite.h // AnimatedSprite.cpp : Handles all sprite animation and rendering of an entity or object.

private members:

float current_frame = 0.0f;
float max_frames = 0.0f;
float delta = 0.0f;
float percentDone = 0.0f;

bool animFinished = false;

SDL_Renderer* renderer = nullptr;

public members:

SDL_RendererFlip flipType = SDL_FLIP_NONE;
SDL_Texture* texture = nullptr;
SDL_Rect animclips [100];
int yfactor = 0
int xfactor = 0;

bool LoadTexture(std::string path, SDL_Renderer* gRenderer);
void BuildAnimation(int row, int cnt, int w, int h, float d);
void Animate(SDL_Rect pos, double angle, SDL_Point* center, SDL_RendererFlip flip, SDL_Rect* frameData);
SDL_Renderer* getRenderer();

current_frame: The current frame playing in the animation.

max_frames: Maximum number of frames in an animation.

delta: Speed per tick to play an animation.

percentDone: % of animation complete.

animFinished: Determines whether the current animation is finished playing, or the animation has just been reset.

renderer: SDL_Renderer* to be displayed to.

flipType: Determines whether to flip horizontal or not. Makes sure object is always facing the way requested.

texture: SDL_Texture to be displayed. Load .png files here!

animclips: An array of sprite rects for a single animation.

yfactor: Offset sprite Y Pos.

xfactor: Offset sprite X Pos.

float getDelta: Animation delta getter.

float percentDone: Animation % complete getter.

bool isFinishedPlaying: Is animation finished? (getter)

void LoadTexture: Loads the texture.

void BuildAnimation: Creates the animation rects stored in animclips.

void Animate: Animates / Draws the texture.

SDL_Renderer* getRenderer: Returns a pointer to the renderer the texture is being displayed to.