AnnexGameDev / Annex

A 2D game development framework
MIT License
3 stars 0 forks source link

IsKeyDown should consider whether the game window is active #7

Closed MatthewChrobak closed 4 years ago

MatthewChrobak commented 5 years ago

The function works as intended, and states whether the key is down or not. But, it can be problematic to process user input while the game window is in the background and another window is the focus.

example: Take a game with arrow keys are used for player movement. By simply using IsKeyDown, if the key is pressed while in another window, the player will still move even if the window is in the background.

Perhaps another state function like IsWindowFocused() is needed?

if (window.IsWindowFocused()) {
    if (window.IsKeyDown(KeyboardKey.Up)) {
        // ...
    }
}