0

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:

  • This one uses if (controller.isButtonPressed(Buttons.LeftThumbstickUp)) but it is the same idea.
    http://create.msdn.com/en-US/education/catalog/sample/game_state_management
  • I realize this one is XNA 2.0 (I'm working with 4.0) but the principle remains
    http://www.sgtconker.com/2010/08/nick-gravelyns-alien-aggressors-tutorial/
  • Also, Chad Carter's "Microsoft XNA Game Studio 3.0 Unleashed" book, on page 530, shows similar code. His system checks the previous gamepad state, so his system won't scroll instantly through several options, but it also doesn't let you scroll at all - each time you want to move up a menu option, you have to move the thumbstick back to center and push it back up again. I am looking for behavior more like when you press and hold a key on your keyboard: one letter appears, a slight delay, and then starts repeating the letter at a measured pace.
pinckerman
  • 4,115
  • 6
  • 33
  • 42
Dave W.
  • 1,576
  • 2
  • 18
  • 29

1 Answers1

1

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.

Joel Martinez
  • 46,929
  • 26
  • 130
  • 185
  • The issue is how to **scroll**. For example, how do I allow the user to simply hold up on the thumbstick and "scroll" through multiple options. Using Chad Carter's system, it would simply move up one option on the menu. But what if the user wants to go up 3 options? He has to press up on the thumbstick three separate times. The Xbox dashboard illustrates this feature. It allows you to hold up on the thumbstick to scroll through all of the menus, but at a human-readable pace. – Dave W. Dec 15 '10 at 04:40
  • 1
    If that's the behavior you want, yeah you're going to have to implement a timer mechanism that dictates when it should scroll. The state should keep track of the last time a scroll was initiated, then, once a given time has elapsed do it again. – Joel Martinez Dec 15 '10 at 16:00