You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
240 lines
7.8 KiB
240 lines
7.8 KiB
#include "animatedSprite.h"
|
|
#include "../../components/base/basicFunctionality.h"
|
|
|
|
animatedSprite::animatedSprite(char* textureFile, int x, int y, int width, int height, int count ) :sdlSprite(x, y, width, height, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = 25;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = true;
|
|
m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
|
|
};
|
|
|
|
animatedSprite::animatedSprite(char* textureFile, int x, int y, int width, int height, int count, int fps, bool byRow):sdlSprite( x, y, width, height, textureFile ) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, int x, int y, int width, int height, int cutx, int cuty, int cutw, int cuth, int count) :sdlSprite(x, y, width, height, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = 25;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = true;
|
|
m_sTexCut.x = cutx; m_sTexCut.y = cuty; m_sTexCut.w = cutw; m_sTexCut.h = cuth;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, int x, int y, int width, int height, int cutx, int cuty, int cutw, int cuth, int count, int fps, bool byRow) :sdlSprite(x, y, width, height, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
m_sTexCut.x = cutx; m_sTexCut.y = cuty; m_sTexCut.w = cutw; m_sTexCut.h = cuth;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, int x, int y, int width, int height, int cutx, int cuty, int cutw, int cuth, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(x, y, width, height, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = cols;
|
|
m_nTexRows = rows;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
m_sTexCut.x = cutx; m_sTexCut.y = cuty; m_sTexCut.w = cutw; m_sTexCut.h = cuth;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, int count) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = 25;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = true;
|
|
m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = cols;
|
|
m_nTexRows = rows;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, SDL_Rect& cut, int count) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = 25;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = true;
|
|
memcpy(&m_sTexCut, &cut, sizeof(SDL_Rect));
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, SDL_Rect& cut, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
memcpy(&m_sTexCut, &cut, sizeof(SDL_Rect));
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, SDL_Rect& cut, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = cols;
|
|
m_nTexRows = rows;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
memcpy(&m_sTexCut, &cut, sizeof(SDL_Rect));
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, int count) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = 25;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = true;
|
|
m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = cols;
|
|
m_nTexRows = rows;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, SDL_Rect* cut, int count) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = 25;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = true;
|
|
memcpy(&m_sTexCut, cut, sizeof(SDL_Rect));
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, SDL_Rect* cut, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = 1;
|
|
m_nTexRows = 1;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
memcpy(&m_sTexCut, cut, sizeof(SDL_Rect));
|
|
};
|
|
animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, SDL_Rect* cut, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
|
|
m_nVisualStage = 0;
|
|
m_nFramesTotal = count;
|
|
m_nTexCols = cols;
|
|
m_nTexRows = rows;
|
|
m_nFPS = fps;
|
|
m_nNextTS = 0;
|
|
m_nIncrementTS = 1000 / m_nFPS;
|
|
m_bInterateRows = byRow;
|
|
memcpy(&m_sTexCut, cut, sizeof(SDL_Rect));
|
|
};
|
|
|
|
animatedSprite::~animatedSprite() {
|
|
|
|
};
|
|
|
|
bool animatedSprite::create(void) {
|
|
if (sdlSprite::create()) {
|
|
if (m_sTexCut.w == 0 && m_sTexCut.h == 0) {
|
|
m_sTexCut.w = m_pTexItem->geopmetry.w;
|
|
m_sTexCut.h = m_pTexItem->geopmetry.h;
|
|
};
|
|
if (m_nTexCols == 1 && m_nTexRows == 1) {
|
|
m_nTexCols = m_sTexCut.w / m_sGeometry.w;
|
|
m_nTexRows = m_sTexCut.h / m_sGeometry.h;
|
|
};
|
|
if(m_nFramesTotal < 1) m_nFramesTotal = m_nTexRows * m_nTexCols;
|
|
m_nVisualStage = 0;
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
void animatedSprite::draw(SDL_Renderer* tPtr) {
|
|
if (!m_bInitComplete)return;
|
|
if (tPtr == NULL)return;
|
|
if (m_nFramesTotal > 0) {
|
|
unsigned __int64 cTS = getMilliseconds();
|
|
if (m_nVisualStage == m_nFramesTotal) m_nVisualStage = 0;
|
|
int c_row, c_col;
|
|
if (m_bInterateRows) {
|
|
c_row = m_nVisualStage / m_nTexCols;
|
|
c_col = m_nVisualStage % m_nTexCols;
|
|
} else {
|
|
c_col = m_nVisualStage / m_nTexRows;
|
|
c_row = m_nVisualStage % m_nTexRows;
|
|
};
|
|
SDL_Rect clip;
|
|
clip.w = m_sGeometry.w;
|
|
clip.h = m_sGeometry.h;
|
|
clip.x = m_sTexCut.x + c_col * clip.w;
|
|
clip.y = m_sTexCut.y + c_row * clip.h;
|
|
//SDL_QueryTexture(m_pTexture, NULL, NULL, &dest.w, &dest.h);
|
|
SDL_RenderCopy(tPtr, m_pTexItem->texture,&clip, &m_sGeometry);
|
|
if (cTS >= m_nNextTS) {
|
|
m_nVisualStage++;
|
|
m_nNextTS = cTS + m_nIncrementTS;
|
|
};
|
|
};
|
|
};
|