I have been developing a game and until now I have been handling input like so:
- Player presses a key
- HandleInput() acknowledges a key is pressed calls a function within the
Playerclass which increments the Players position by a pre-determined amount.
- Update() sets the players sprite to be at the players position.
- Draw() renders the players sprite.
- Return to Step 1.
Now my question is this, should I continue to run my loop in this way or should I implement the following:
- HandleInput() sets a state within the
Playerclass which when Update() is called the Player object checks if it is in a state of motion and updates its location appropriately, before updating the sprite to its new location.
This question arose within me while I was altering my loop so that only the Update() function had a maximum refresh rate (60 cycles per second) and I realized I was unsure how I should appropriately communicate events to the objects on how they should act.
I did not include any code as we're discussing in pseudo-code if you feel some is required let me know.