我试图从这个模块导入Gamepad类,但我总是收到一个错误“无效参数,没有找到合适的构造函数”--这是我的代码:
const { Gamepad } = require('@nodert-win10-20h1/windows.gaming.input')
const gamepad = new Gamepad()如果我试图使用console.log Gamepad,我在控制台中得到了这样的信息:
Gamepad [Function: Gamepad] {
castFrom: [Function: castFrom],
fromGameController: [Function: fromGameController],
gamepads: Windows::Foundation::Collections:IVectorView {
__winRtInstance__: true
}
}游戏垫是一个函数。
也许有人可以给我链接到这个模块的文档,或者解释我如何使用它。
发布于 2021-02-08 13:17:49
这里,我能读到:
此模块公开的API (几乎)与http://msdn.microsoft.com/en-us/library/windows/apps/Windows.Gaming.Input.aspx中列出的API (几乎)相同。
在API中,您可以读到:
不能直接创建Gamepad类的实例;相反,Gamepad类的实例是通过列出所有连接的游戏垫的Gamepad.Gamepads属性或通过Gamepad.GamepadAdded事件检索的。
因此,我认为应该(非常粗略地)使用:
const { Gamepad } = require('@nodert-win10-20h1/windows.gaming.input');
const firstGamePad = GamePad.gamepads.IndexOf(0); //retrieve the first GP found
let currentInput = firstGamePad.GetCurrentReading();// or something like this, just check firstGamePad propertieshttps://stackoverflow.com/questions/66101303
复制相似问题