I’ve been implementing Flipbooks from Paper2D to show animations of my character in a 3D world with 2D graphics. What I’m trying to acheive is my walking animation to play when I walk forwards, and my idle animation to play when no movement keys are held. Currently doing that through a bit of bulky code that looks like this:
void UPlayerAnimationController::UpdateAnimation()
{
m_CurrentAnimation->bVisible = false;
// If idle, use one of our idle animations
if (m_IsIdle)
{
switch (m_CurrentDirection)
{
case EDirection::Forwards:
m_CurrentAnimation = m_IdleForwards;
break;
case EDirection::Backwards:
m_CurrentAnimation = m_IdleBackwards;
break;
case EDirection::Left:
m_CurrentAnimation = m_IdleLeft;
break;
case EDirection::Right:
m_CurrentAnimation = m_IdleRight;
break;
default:
UE_LOG(LogTemp, Fatal, TEXT("Somehow, we've not got a direction which we should be updating to. This is bad."));
return;
}
}
// If not idle, assume we're looking for a walking animation
else
{
switch (m_CurrentDirection)
{
case EDirection::Forwards:
m_CurrentAnimation = m_WalkForwards;
break;
case EDirection::Backwards:
m_CurrentAnimation = m_WalkBackwards;
break;
case EDirection::Left:
m_CurrentAnimation = m_WalkLeft;
break;
case EDirection::Right:
m_CurrentAnimation = m_WalkRight;
break;
default:
UE_LOG(LogTemp, Fatal, TEXT("Somehow, we've not got a direction which we should be updating to. This is bad."));
return;
}
}
m_CurrentAnimation->bVisible = true;
}
Before using the above code, I have loaded all the flipbooks required for my animation at load time in UFlipbookComponent variables, I set all the the bVisible property of all UFlipbookComponents to false, then I point the m_CurrentAnimation pointer to the flipbook I want to use, and set the m_CurrentAnimation to be visible.
The issue I’m facing is that whenever the animation changes, a sprite (the keyframe that was being played on the animation as it is stopped) will persist in the world, even though bVisible is set to false before changing the current animation pointer to point at a different animation.
My only thoughts on what is causing this are that flipbooks may work by creating and destroying sprites, by me changing the animation it is somehow not destroying the sprite? If anyone has any more information I can read on this or proposed solutions it would be much appreciated!