Reversing animated sprites
- by brandon sedgwick
I have created a sprite sheet of which consists of 6 frames with a character moving legs each frame, now I have coded it so that the animation is running successfully from frame 1 to 6, however I am trying to reverse this so then when it goes from 1 to 6 instead of restarting it go's 6 to 1 in a continuous loop. The coding for current animation is:
void SpriteGame::Update(int tickTotal, int tickDelta)
{
//This is where you manage the state of game objects
if ( tickTotal >= this->playerLastFrameChange + 4)
{
//Four ticks have elapsed since the last frame change
this->playerFrame = this->playerFrame + 1;
this->playerLastFrameChange = tickTotal; //We've just changed the frame
if (this->playerFrame >= this->playerSheetLength)
{
this->playerFrame = playerLastFrameChange + 4;
}
//Frame has changed so change the source rectangle
this->playerSourceRect->left = this->playerFrame * 64;
this->playerSourceRect->top = 0;
this->playerSourceRect->right = (this->playerFrame + 1) * 64;
this->playerSourceRect->bottom = 64;
}
}
any help please I am using DirectX11 as thats what we are being told to use as its for an win 8 game.