In our game created with c++ and sdl we are having difficulty delegating how the main character should be controlled. We have a keyboard class and a sprite class for the main character, but are unsure if the main character should have an instance of the keyboard class or if keyboard input should be done through the game loop. If you need anymore information I would be happy to provide it, thanks in advance for any help.
Take the 2-minute tour
×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.
Your main character class should not have a reference to the keyboard or any input-related class. Input should be handled in the game loop, or preferably a dedicated input class, decoupled from other entities so they'll only need to respond to abstract actions, not raw input. Not all input is related to your characters and and not all types of input devices are the same, so your best bet is to separate the input handling into several stages so you can handle it contextually e.g.
This will make it easier for you to implement new actions, control schemes, input devices or multiplayer controls. |
|||||||||
|