I'm having trouble transitioning my walking to idle animations.
Maybe there's a better way to go about this?
The problem: I can check for NO key presses on the keyboard, but it causes the walking animation to display only the first frame and not the full animation.
The question: How can I change this so that when the user is done walking, it will change the state back to "Idle" without conflicting with the animations of walking left and right.
private void UpdateMovement(KeyboardState aCurrentKeyboardState, GameTime gameTime)
{
timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; //Framerate control
if (timeSinceLastFrame > millisecondsPerFrame) //Framerate control
{
timeSinceLastFrame -= millisecondsPerFrame; //Framerate control
//Idle if no keys are down
if (mCurrentState == State.Idle)
{
Position.Y = 210;
currentImageIndex++;
if (currentImageIndex < 17 || currentImageIndex > 23)
currentImageIndex = 17;
}
//Walk Left
if (aCurrentKeyboardState.IsKeyDown(Keys.Left))
{
mCurrentState = State.Walking;
if (currentImageIndex < 8 || currentImageIndex > 15)
currentImageIndex = 8;
Position.Y = 200;
currentImageIndex++;
Position.X += MOVE_LEFT;
if (currentImageIndex > 15)
currentImageIndex = 8;
}
//Walk Right
if (aCurrentKeyboardState.IsKeyDown(Keys.Right))
{
mCurrentState = State.Walking;
if (currentImageIndex > 7)
currentImageIndex = 0;
Position.Y = 200; ;
currentImageIndex++;
Position.X += MOVE_RIGHT;
if (currentImageIndex > 7)
currentImageIndex = 0;
}
if (aCurrentKeyboardState.IsKeyDown(Keys.None))
mCurrentState = State.Idle;
}
}