-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Select character with keyboard #152
Select character with keyboard #152
Conversation
@@ -168,6 +174,12 @@ protected virtual async Task DeleteButtonClick() | |||
protected virtual void DoUpdateLogic(GameTime gameTime) | |||
{ | |||
_characterControl.Update(gameTime); | |||
|
|||
var keyboardState = _userInputProvider.CurrentKeyState; | |||
if (keyboardState.IsKeyDown((Microsoft.Xna.Framework.Input.Keys)49+_characterIndex)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to check currentState.KeyUp and previousState.KeyDown for this, otherwise holding the key will spawn a bunch of tasks. The interlocked guard happens in LoginButtonClick
so it won't stop the tasks from being started (and then immediately exiting).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched to using IsKeyPressedOnce
@@ -168,6 +174,12 @@ protected virtual async Task DeleteButtonClick() | |||
protected virtual void DoUpdateLogic(GameTime gameTime) | |||
{ | |||
_characterControl.Update(gameTime); | |||
|
|||
var keyboardState = _userInputProvider.CurrentKeyState; | |||
if (keyboardState.IsKeyDown((Microsoft.Xna.Framework.Input.Keys)49+_characterIndex)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do Keys.D1
+_characterIndex? I think C# is pretty flexible with adding values to enums in this way.
Also, just add the using statement instead of fully qualifying the type here. FYI you can easily add the using Microsoft.Xna.Framework.Input
via the keyboard shortcut CTRL+. in VS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
58eb7f7
to
73a7efc
Compare
73a7efc
to
e727b88
Compare
Seemed like a fun feature to implement and get my hands dirty with the client.
No idea if this is the "correct" way to deal with adding keyboard handling to a component.
Let me know if there's a better way and I can fix it :)