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.

239 lines
7.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "animatedSprite.h"
  2. #include "../../components/base/basicFunctionality.h"
  3. animatedSprite::animatedSprite(char* textureFile, int x, int y, int width, int height, int count ) :sdlSprite(x, y, width, height, textureFile) {
  4. m_nVisualStage = 0;
  5. m_nFramesTotal = count;
  6. m_nTexCols = 1;
  7. m_nTexRows = 1;
  8. m_nFPS = 25;
  9. m_nNextTS = 0;
  10. m_nIncrementTS = 1000 / m_nFPS;
  11. m_bInterateRows = true;
  12. m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
  13. };
  14. animatedSprite::animatedSprite(char* textureFile, int x, int y, int width, int height, int count, int fps, bool byRow):sdlSprite( x, y, width, height, textureFile ) {
  15. m_nVisualStage = 0;
  16. m_nFramesTotal = count;
  17. m_nTexCols = 1;
  18. m_nTexRows = 1;
  19. m_nFPS = fps;
  20. m_nNextTS = 0;
  21. m_nIncrementTS = 1000 / m_nFPS;
  22. m_bInterateRows = byRow;
  23. m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
  24. };
  25. 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) {
  26. m_nVisualStage = 0;
  27. m_nFramesTotal = count;
  28. m_nTexCols = 1;
  29. m_nTexRows = 1;
  30. m_nFPS = 25;
  31. m_nNextTS = 0;
  32. m_nIncrementTS = 1000 / m_nFPS;
  33. m_bInterateRows = true;
  34. m_sTexCut.x = cutx; m_sTexCut.y = cuty; m_sTexCut.w = cutw; m_sTexCut.h = cuth;
  35. };
  36. 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) {
  37. m_nVisualStage = 0;
  38. m_nFramesTotal = count;
  39. m_nTexCols = 1;
  40. m_nTexRows = 1;
  41. m_nFPS = fps;
  42. m_nNextTS = 0;
  43. m_nIncrementTS = 1000 / m_nFPS;
  44. m_bInterateRows = byRow;
  45. m_sTexCut.x = cutx; m_sTexCut.y = cuty; m_sTexCut.w = cutw; m_sTexCut.h = cuth;
  46. };
  47. 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) {
  48. m_nVisualStage = 0;
  49. m_nFramesTotal = count;
  50. m_nTexCols = cols;
  51. m_nTexRows = rows;
  52. m_nFPS = fps;
  53. m_nNextTS = 0;
  54. m_nIncrementTS = 1000 / m_nFPS;
  55. m_bInterateRows = byRow;
  56. m_sTexCut.x = cutx; m_sTexCut.y = cuty; m_sTexCut.w = cutw; m_sTexCut.h = cuth;
  57. };
  58. animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, int count) :sdlSprite(geom, textureFile) {
  59. m_nVisualStage = 0;
  60. m_nFramesTotal = count;
  61. m_nTexCols = 1;
  62. m_nTexRows = 1;
  63. m_nFPS = 25;
  64. m_nNextTS = 0;
  65. m_nIncrementTS = 1000 / m_nFPS;
  66. m_bInterateRows = true;
  67. m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
  68. };
  69. animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
  70. m_nVisualStage = 0;
  71. m_nFramesTotal = count;
  72. m_nTexCols = 1;
  73. m_nTexRows = 1;
  74. m_nFPS = fps;
  75. m_nNextTS = 0;
  76. m_nIncrementTS = 1000 / m_nFPS;
  77. m_bInterateRows = byRow;
  78. m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
  79. };
  80. animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
  81. m_nVisualStage = 0;
  82. m_nFramesTotal = count;
  83. m_nTexCols = cols;
  84. m_nTexRows = rows;
  85. m_nFPS = fps;
  86. m_nNextTS = 0;
  87. m_nIncrementTS = 1000 / m_nFPS;
  88. m_bInterateRows = byRow;
  89. m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
  90. };
  91. animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, SDL_Rect& cut, int count) :sdlSprite(geom, textureFile) {
  92. m_nVisualStage = 0;
  93. m_nFramesTotal = count;
  94. m_nTexCols = 1;
  95. m_nTexRows = 1;
  96. m_nFPS = 25;
  97. m_nNextTS = 0;
  98. m_nIncrementTS = 1000 / m_nFPS;
  99. m_bInterateRows = true;
  100. memcpy(&m_sTexCut, &cut, sizeof(SDL_Rect));
  101. };
  102. animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, SDL_Rect& cut, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
  103. m_nVisualStage = 0;
  104. m_nFramesTotal = count;
  105. m_nTexCols = 1;
  106. m_nTexRows = 1;
  107. m_nFPS = fps;
  108. m_nNextTS = 0;
  109. m_nIncrementTS = 1000 / m_nFPS;
  110. m_bInterateRows = byRow;
  111. memcpy(&m_sTexCut, &cut, sizeof(SDL_Rect));
  112. };
  113. animatedSprite::animatedSprite(char* textureFile, SDL_Rect& geom, SDL_Rect& cut, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
  114. m_nVisualStage = 0;
  115. m_nFramesTotal = count;
  116. m_nTexCols = cols;
  117. m_nTexRows = rows;
  118. m_nFPS = fps;
  119. m_nNextTS = 0;
  120. m_nIncrementTS = 1000 / m_nFPS;
  121. m_bInterateRows = byRow;
  122. memcpy(&m_sTexCut, &cut, sizeof(SDL_Rect));
  123. };
  124. animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, int count) :sdlSprite(geom, textureFile) {
  125. m_nVisualStage = 0;
  126. m_nFramesTotal = count;
  127. m_nTexCols = 1;
  128. m_nTexRows = 1;
  129. m_nFPS = 25;
  130. m_nNextTS = 0;
  131. m_nIncrementTS = 1000 / m_nFPS;
  132. m_bInterateRows = true;
  133. m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
  134. };
  135. animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
  136. m_nVisualStage = 0;
  137. m_nFramesTotal = count;
  138. m_nTexCols = 1;
  139. m_nTexRows = 1;
  140. m_nFPS = fps;
  141. m_nNextTS = 0;
  142. m_nIncrementTS = 1000 / m_nFPS;
  143. m_bInterateRows = byRow;
  144. m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
  145. };
  146. animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
  147. m_nVisualStage = 0;
  148. m_nFramesTotal = count;
  149. m_nTexCols = cols;
  150. m_nTexRows = rows;
  151. m_nFPS = fps;
  152. m_nNextTS = 0;
  153. m_nIncrementTS = 1000 / m_nFPS;
  154. m_bInterateRows = byRow;
  155. m_sTexCut.x = 0; m_sTexCut.y = 0; m_sTexCut.w = 0; m_sTexCut.h = 0;
  156. };
  157. animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, SDL_Rect* cut, int count) :sdlSprite(geom, textureFile) {
  158. m_nVisualStage = 0;
  159. m_nFramesTotal = count;
  160. m_nTexCols = 1;
  161. m_nTexRows = 1;
  162. m_nFPS = 25;
  163. m_nNextTS = 0;
  164. m_nIncrementTS = 1000 / m_nFPS;
  165. m_bInterateRows = true;
  166. memcpy(&m_sTexCut, cut, sizeof(SDL_Rect));
  167. };
  168. animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, SDL_Rect* cut, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
  169. m_nVisualStage = 0;
  170. m_nFramesTotal = count;
  171. m_nTexCols = 1;
  172. m_nTexRows = 1;
  173. m_nFPS = fps;
  174. m_nNextTS = 0;
  175. m_nIncrementTS = 1000 / m_nFPS;
  176. m_bInterateRows = byRow;
  177. memcpy(&m_sTexCut, cut, sizeof(SDL_Rect));
  178. };
  179. animatedSprite::animatedSprite(char* textureFile, SDL_Rect* geom, SDL_Rect* cut, int cols, int rows, int count, int fps, bool byRow) :sdlSprite(geom, textureFile) {
  180. m_nVisualStage = 0;
  181. m_nFramesTotal = count;
  182. m_nTexCols = cols;
  183. m_nTexRows = rows;
  184. m_nFPS = fps;
  185. m_nNextTS = 0;
  186. m_nIncrementTS = 1000 / m_nFPS;
  187. m_bInterateRows = byRow;
  188. memcpy(&m_sTexCut, cut, sizeof(SDL_Rect));
  189. };
  190. animatedSprite::~animatedSprite() {
  191. };
  192. bool animatedSprite::create(void) {
  193. if (sdlSprite::create()) {
  194. if (m_sTexCut.w == 0 && m_sTexCut.h == 0) {
  195. m_sTexCut.w = m_pTexItem->geopmetry.w;
  196. m_sTexCut.h = m_pTexItem->geopmetry.h;
  197. };
  198. if (m_nTexCols == 1 && m_nTexRows == 1) {
  199. m_nTexCols = m_sTexCut.w / m_sGeometry.w;
  200. m_nTexRows = m_sTexCut.h / m_sGeometry.h;
  201. };
  202. if(m_nFramesTotal < 1) m_nFramesTotal = m_nTexRows * m_nTexCols;
  203. m_nVisualStage = 0;
  204. return true;
  205. };
  206. return false;
  207. };
  208. void animatedSprite::draw(SDL_Renderer* tPtr) {
  209. if (!m_bInitComplete)return;
  210. if (tPtr == NULL)return;
  211. if (m_nFramesTotal > 0) {
  212. unsigned __int64 cTS = getMilliseconds();
  213. if (m_nVisualStage == m_nFramesTotal) m_nVisualStage = 0;
  214. int c_row, c_col;
  215. if (m_bInterateRows) {
  216. c_row = m_nVisualStage / m_nTexCols;
  217. c_col = m_nVisualStage % m_nTexCols;
  218. } else {
  219. c_col = m_nVisualStage / m_nTexRows;
  220. c_row = m_nVisualStage % m_nTexRows;
  221. };
  222. SDL_Rect clip;
  223. clip.w = m_sGeometry.w;
  224. clip.h = m_sGeometry.h;
  225. clip.x = m_sTexCut.x + c_col * clip.w;
  226. clip.y = m_sTexCut.y + c_row * clip.h;
  227. //SDL_QueryTexture(m_pTexture, NULL, NULL, &dest.w, &dest.h);
  228. SDL_RenderCopy(tPtr, m_pTexItem->texture,&clip, &m_sGeometry);
  229. if (cTS >= m_nNextTS) {
  230. m_nVisualStage++;
  231. m_nNextTS = cTS + m_nIncrementTS;
  232. };
  233. };
  234. };