Key Input Key.None return false without buttons pressed

Hi there,

currently I’m building my first game, after doing some tutorials on making sprites and programming in C# (I have basic experience in programming).
Everything is working fine and I managed to get a player animation running in multiple directions. Now I am trying to pause the animation while the player is standing still (it now keeps looping as walking while standing still)

I thought of building a pause for now, which is pausing the animation at the first frame when true.
This is working properly now.
However the following doesnt work:
if (keyboardState.IsKeyDown(Keys.None)) { AnimationLeft.Pause = true; AnimationRight.Pause = true; AnimationDown.Pause = true; AnimationUp.Pause = true; }

When using any other key it pauses the animations which works like a charm.
So I used some console.Writeline to debug.
Console.WriteLine(keyboardState.IsKeyDown(Keys.None)); Console.WriteLine(keyboardState.GetPressedKeys());
The above returns the following during running:
False Microsoft.Xna.Framework.Input.Keys[]

So now my question is why the keys.None is returning a false, where if I request the pressed keys I get none.
Can anybody help me out here?

Additionaly,
I want to start working from a single animation-instance of player movement but still thinking a proper method, tips are welcome :slight_smile:

Keys.None is a default value that cannot be pressed, and it doesn’t mean that no keys are pressed. If you call keyboardState.GetPressedKeyCount() you’ll also see that it shows 0 when nothing is pressed. Using another key is the correct way to do it.

I recommend reading up on finite state machines regarding your player animations. In short, you’d have a state while your character is running, and on the frame no directions are pressed, put them in the “standing” state, which plays the animation upon entry. If a direction is pressed in the “standing” state, the player would transition to the “running” state which plays the running animation.

Thank you for the sound explanation.
The GetPressedKeyCount() gives me an error code that it is not part of the method.
I looked in the documentation and noticed it is Version 3.8.0 from the Monogame framework:
I currently run on 3.7.0 with Visual studio 2019, since 3.7.1 gave me some issues with both visual studio 2019 and 17.
For now I have a workaround which is working as well.

Thanks for the tips on finite state machines, I’ll do some reading up. For now I have that solution, I just had a very crude way in programming it, I looked into my code and made some slight changes so that I can alter the position of the drawing box of the animation and accessing different parts of my sprite. I can now make a single instance of an animation and easily alter the integer and go through a different animation cycle.