I am working on developing menu systems for a very simple pong test I made, and have run into some trouble with the thumbsticks. Several examples I have seen show the code to move up and down options on a menu screen as simply:
if (controller.Thumbsticks.Left.Y > 0.5f) MenuUp();
While this works in theory, this test is run every frame (in the Update()
call, ostensibly), checking the controller state roughly 60 times a second. Since the average user will hold the thumbstick up for probably a quarter second at least, the result is that a tap up on the controller thumbstick cycles through the entire menu almost instantly.
I could probably implement some kind of complicated timer system, where it checks how long since the last menu item change and how long the thumbstick has been held up, but none of the samples on the web I have found use such a complicated timing system. Am I missing something?
Edit: Andrew asked in the comment below for links to these tutorials I have found:
if (controller.isButtonPressed(Buttons.LeftThumbstickUp))
but it is the same idea.You've linked several successful tutorials which demonstrate this technique. What exactly is the question here? The basic premise is as you state, if you just check/move every frame the result will be incomprehensible to the user.
The simplest option is to keep the "previous state" of the controller. And if "down" was already pressed in the last frame, then you refrain from moving the menu option. This makes it so that one user action for down is processed only once.