【发布时间】:2017-01-24 04:04:01
【问题描述】:
我开发了一个可以在 XBOX 上运行的 UWP 应用。
我想检测游戏手柄控制器上的按钮是否被按下(A B X 或 Y)。
我认为我需要使用点击事件?如果是在点击事件上,我需要在点击事件中签到什么?
查看这篇文章,确定是否按下了触发器..
Controller support for Xbox one in Windows UWP
/*
* Note: I have not tested this code.
* If it is incorrect, please do edit with the fix.
*/
using Windows.Gaming.Input;
// bla bla bla boring stuff...
// Get the first controller
var controller = Gamepad.Gamepads.First();
// Get the current state
var reading = controller.GetCurrentReading();
// Check to see if the left trigger was depressed about half way down
if (reading.LeftTrigger == 0.5;)
{
// Do whatever
}
我认为有一种等效的方法可以检查是否按下了 ABXY 按钮之一?。下次有机会我会检查的。
另一方面,这篇博文看起来对刚开始为 Xbox One 开发 UWP 的人非常有用 http://grogansoft.com/blog/?p=1278
更新: 看起来我可以调用 GetCurrentReading() 来获得 GamepadReading 结构。并从中获取GamepadButtons 的状态。
【问题讨论】: