-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roman Shapiro
committed
Aug 16, 2020
1 parent
2bcc453
commit e717ff1
Showing
3 changed files
with
108 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
samples/SpriteFontPlus.Samples.DynamicSpriteFont/KeyboardUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Microsoft.Xna.Framework.Input; | ||
using System; | ||
|
||
namespace SpriteFontPlus.Samples.TtfBaking | ||
{ | ||
public static class KeyboardUtils | ||
{ | ||
private static bool _beginCalled = false; | ||
private static KeyboardState _state, _oldState; | ||
|
||
public static void Begin() | ||
{ | ||
if (_beginCalled) | ||
{ | ||
throw new Exception("Begin was already called"); | ||
} | ||
|
||
_state = Keyboard.GetState(); | ||
_beginCalled = true; | ||
} | ||
|
||
public static bool IsPressed(Keys key) | ||
{ | ||
if (!_beginCalled) | ||
{ | ||
throw new Exception("Begin wasnt called"); | ||
} | ||
|
||
return _state.IsKeyDown(key) && !_oldState.IsKeyDown(key); | ||
} | ||
|
||
public static void End() | ||
{ | ||
if (!_beginCalled) | ||
{ | ||
throw new Exception("Begin wasnt called"); | ||
} | ||
|
||
_oldState = _state; | ||
_beginCalled = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters