Skip to content

Commit 30d726b

Browse files
committed
Added advanced rendering. Changed abs() to -1 * when playing animations as it's faster and just as safe
1 parent ba4d856 commit 30d726b

File tree

2 files changed

+102
-3
lines changed

2 files changed

+102
-3
lines changed

include/spritetools_render.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,29 @@ void ST_RenderAnimationPrevious(st_animation *animation, int x, int y);
165165
/* Takes a pointer to an animation and a position */
166166
void ST_RenderAnimationPlay(st_animation *animation, int x, int y);
167167

168+
169+
/****************************************\
170+
|* Advanced Animation Rendering *|
171+
\****************************************/
172+
/* The following functions also take a scalar multiplier, */
173+
/* rotation in radians, and red, green, blue, and alpha of a */
174+
/* color to blend with */
175+
176+
177+
void ST_RenderAnimationCurrentAdvanced(st_animation *animation, int x, int y,
178+
double scale, double rotate,
179+
u8 red, u8 green, u8 blue, u8 alpha);
180+
181+
void ST_RenderAnimationNextAdvanced(st_animation *animation, int x, int y,
182+
double scale, double rotate,
183+
u8 red, u8 green, u8 blue, u8 alpha);
184+
185+
void ST_RenderAnimationPreviousAdvanced(st_animation *animation, int x, int y,
186+
double scale, double rotate,
187+
u8 red, u8 green, u8 blue, u8 alpha);
188+
189+
void ST_RenderAnimationPlayAdvanced(st_animation *animation, int x, int y,
190+
double scale, double rotate,
191+
u8 red, u8 green, u8 blue, u8 alpha);
192+
168193
#endif

source/spritetools_render.c

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void ST_RenderAnimationNext(st_animation *animation, int x, int y)
257257
animation->currentFrame++;
258258
if(animation->currentFrame >= animation->length)
259259
animation->currentFrame = animation->loopFrame;
260-
ST_RenderFramePosition(animation->frames[animation->currentFrame], x, y);
260+
ST_RenderAnimationCurrent(animation, x, y);
261261
}
262262

263263
/* Draw the previous frame of an animation at given position */
@@ -268,7 +268,7 @@ void ST_RenderAnimationPrevious(st_animation *animation, int x, int y)
268268
animation->currentFrame--;
269269
if(animation->currentFrame >= animation->length)
270270
animation->currentFrame = animation->loopFrame;
271-
ST_RenderFramePosition(animation->frames[animation->currentFrame], x, y);
271+
ST_RenderAnimationCurrent(animation, x, y);
272272
}
273273

274274
/* Plays an animation at given position */
@@ -291,7 +291,7 @@ void ST_RenderAnimationPlay(st_animation *animation, int x, int y)
291291
}
292292
else
293293
{
294-
if (animation->ftn > abs(animation->fpf))
294+
if (animation->ftn > -1 * animation->fpf)
295295
{
296296
animation->ftn = 0;
297297
ST_RenderAnimationPrevious(animation, x, y);
@@ -302,3 +302,77 @@ void ST_RenderAnimationPlay(st_animation *animation, int x, int y)
302302
}
303303
}
304304
}
305+
306+
307+
/****************************************\
308+
|* Advanced Animation Rendering *|
309+
\****************************************/
310+
/* The following functions also take a scalar multiplier, */
311+
/* rotation in radians, and red, green, blue, and alpha of a */
312+
/* color to blend with */
313+
314+
315+
void ST_RenderAnimationCurrentAdvanced(st_animation *animation, int x, int y,
316+
double scale, double rotate,
317+
u8 red, u8 green, u8 blue, u8 alpha)
318+
{
319+
ST_RenderFramePositionAdvanced(animation->frames[animation->currentFrame],
320+
x, y, scale, rotate, red, green, blue, alpha);
321+
}
322+
323+
void ST_RenderAnimationNextAdvanced(st_animation *animation, int x, int y,
324+
double scale, double rotate,
325+
u8 red, u8 green, u8 blue, u8 alpha)
326+
{
327+
animation->currentFrame++;
328+
if(animation->currentFrame >= animation->length)
329+
animation->currentFrame = animation->loopFrame;
330+
ST_RenderAnimationCurrentAdvanced(animation, x, y,
331+
scale, rotate, red, green, blue, alpha);
332+
}
333+
334+
void ST_RenderAnimationPreviousAdvanced(st_animation *animation, int x, int y,
335+
double scale, double rotate,
336+
u8 red, u8 green, u8 blue, u8 alpha)
337+
{
338+
animation->currentFrame--;
339+
if(animation->currentFrame >= animation->length)
340+
animation->currentFrame = animation->loopFrame;
341+
ST_RenderAnimationCurrentAdvanced(animation, x, y,
342+
scale, rotate, red, green, blue, alpha);
343+
}
344+
345+
void ST_RenderAnimationPlayAdvanced(st_animation *animation, int x, int y,
346+
double scale, double rotate,
347+
u8 red, u8 green, u8 blue, u8 alpha)
348+
{
349+
animation->ftn++;
350+
if (animation->fpf >= 0)
351+
{
352+
if (animation->ftn > animation->fpf)
353+
{
354+
animation->ftn = 0;
355+
ST_RenderAnimationNextAdvanced(animation, x, y,
356+
scale, rotate, red, green, blue, alpha);
357+
}
358+
else
359+
{
360+
ST_RenderAnimationCurrentAdvanced(animation, x, y,
361+
scale, rotate, red, green, blue, alpha);
362+
}
363+
}
364+
else
365+
{
366+
if (animation->ftn > -1 * animation->fpf)
367+
{
368+
animation->ftn = 0;
369+
ST_RenderAnimationPreviousAdvanced(animation, x, y,
370+
scale, rotate, red, green, blue, alpha);
371+
}
372+
else
373+
{
374+
ST_RenderAnimationCurrentAdvanced(animation, x, y,
375+
scale, rotate, red, green, blue, alpha);
376+
}
377+
}
378+
}

0 commit comments

Comments
 (0)