Skip to content

Commit

Permalink
Added advanced rendering. Changed abs() to -1 * when playing animatio…
Browse files Browse the repository at this point in the history
…ns as it's faster and just as safe
  • Loading branch information
BtheDestroyer committed Dec 31, 2016
1 parent ba4d856 commit 30d726b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 3 deletions.
25 changes: 25 additions & 0 deletions include/spritetools_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,29 @@ void ST_RenderAnimationPrevious(st_animation *animation, int x, int y);
/* Takes a pointer to an animation and a position */
void ST_RenderAnimationPlay(st_animation *animation, int x, int y);


/****************************************\
|* Advanced Animation Rendering *|
\****************************************/
/* The following functions also take a scalar multiplier, */
/* rotation in radians, and red, green, blue, and alpha of a */
/* color to blend with */


void ST_RenderAnimationCurrentAdvanced(st_animation *animation, int x, int y,
double scale, double rotate,
u8 red, u8 green, u8 blue, u8 alpha);

void ST_RenderAnimationNextAdvanced(st_animation *animation, int x, int y,
double scale, double rotate,
u8 red, u8 green, u8 blue, u8 alpha);

void ST_RenderAnimationPreviousAdvanced(st_animation *animation, int x, int y,
double scale, double rotate,
u8 red, u8 green, u8 blue, u8 alpha);

void ST_RenderAnimationPlayAdvanced(st_animation *animation, int x, int y,
double scale, double rotate,
u8 red, u8 green, u8 blue, u8 alpha);

#endif
80 changes: 77 additions & 3 deletions source/spritetools_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void ST_RenderAnimationNext(st_animation *animation, int x, int y)
animation->currentFrame++;
if(animation->currentFrame >= animation->length)
animation->currentFrame = animation->loopFrame;
ST_RenderFramePosition(animation->frames[animation->currentFrame], x, y);
ST_RenderAnimationCurrent(animation, x, y);
}

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

/* Plays an animation at given position */
Expand All @@ -291,7 +291,7 @@ void ST_RenderAnimationPlay(st_animation *animation, int x, int y)
}
else
{
if (animation->ftn > abs(animation->fpf))
if (animation->ftn > -1 * animation->fpf)
{
animation->ftn = 0;
ST_RenderAnimationPrevious(animation, x, y);
Expand All @@ -302,3 +302,77 @@ void ST_RenderAnimationPlay(st_animation *animation, int x, int y)
}
}
}


/****************************************\
|* Advanced Animation Rendering *|
\****************************************/
/* The following functions also take a scalar multiplier, */
/* rotation in radians, and red, green, blue, and alpha of a */
/* color to blend with */


void ST_RenderAnimationCurrentAdvanced(st_animation *animation, int x, int y,
double scale, double rotate,
u8 red, u8 green, u8 blue, u8 alpha)
{
ST_RenderFramePositionAdvanced(animation->frames[animation->currentFrame],
x, y, scale, rotate, red, green, blue, alpha);
}

void ST_RenderAnimationNextAdvanced(st_animation *animation, int x, int y,
double scale, double rotate,
u8 red, u8 green, u8 blue, u8 alpha)
{
animation->currentFrame++;
if(animation->currentFrame >= animation->length)
animation->currentFrame = animation->loopFrame;
ST_RenderAnimationCurrentAdvanced(animation, x, y,
scale, rotate, red, green, blue, alpha);
}

void ST_RenderAnimationPreviousAdvanced(st_animation *animation, int x, int y,
double scale, double rotate,
u8 red, u8 green, u8 blue, u8 alpha)
{
animation->currentFrame--;
if(animation->currentFrame >= animation->length)
animation->currentFrame = animation->loopFrame;
ST_RenderAnimationCurrentAdvanced(animation, x, y,
scale, rotate, red, green, blue, alpha);
}

void ST_RenderAnimationPlayAdvanced(st_animation *animation, int x, int y,
double scale, double rotate,
u8 red, u8 green, u8 blue, u8 alpha)
{
animation->ftn++;
if (animation->fpf >= 0)
{
if (animation->ftn > animation->fpf)
{
animation->ftn = 0;
ST_RenderAnimationNextAdvanced(animation, x, y,
scale, rotate, red, green, blue, alpha);
}
else
{
ST_RenderAnimationCurrentAdvanced(animation, x, y,
scale, rotate, red, green, blue, alpha);
}
}
else
{
if (animation->ftn > -1 * animation->fpf)
{
animation->ftn = 0;
ST_RenderAnimationPreviousAdvanced(animation, x, y,
scale, rotate, red, green, blue, alpha);
}
else
{
ST_RenderAnimationCurrentAdvanced(animation, x, y,
scale, rotate, red, green, blue, alpha);
}
}
}

1 comment on commit 30d726b

@BtheDestroyer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.