GUI 的摇杆控制在菜单选项之间循环过快
我正在为我所做的一个非常简单的乒乓球测试开发菜单系统,并且在拇指杆方面遇到了一些麻烦。我见过的几个示例显示了在菜单屏幕上上下移动选项的代码,如下所示:
if (controller.Thumbsticks.Left.Y > 0.5f) MenuUp();
虽然这在理论上可行,但此测试每帧都运行(表面上在 Update()
调用中) ,每秒检查控制器状态大约 60 次。由于普通用户将按住拇指杆至少四分之一秒,因此点击控制器拇指杆几乎会立即循环浏览整个菜单。
我可能可以实现某种复杂的计时器系统,它检查自上次菜单项更改以来多长时间以及拇指杆已保持多长时间,但我发现网络上的示例都没有使用如此复杂的计时系统。我错过了什么吗?
编辑:安德鲁在下面的评论中询问我找到的这些教程的链接:
- 这个使用
if (controller.isButtonPressed(Buttons.LeftThumbstickUp))
但它是相同的想法。
http://create.msdn.com/en-US/education/catalog /sample/game_state_management - 我意识到这是 XNA 2.0(我正在使用 4.0),但原则仍然存在
http://www.sgtconker.com/2010/08/ nick-gravelyns-alien-aggressors-tutorial/ - 另外,Chad Carter 的“Microsoft XNA Game Studio 3.0 Unleashed”一书(第 530 页)也显示了类似的代码。他的系统会检查之前的游戏手柄状态,因此他的系统不会立即滚动浏览多个选项,但它也根本不允许您滚动 - 每次您想要向上移动菜单选项时,您必须将拇指杆移回中心并再次向上推。我正在寻找更像当你按住键盘上的一个键时的行为:出现一个字母,稍有延迟,然后开始以有节奏的速度重复该字母。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.