开发者

Thumbstick control of GUI cycles through menu options too fast

开发者 https://www.devze.com 2023-01-30 10:29 出处:网络
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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消