游戏手柄

这篇翻译不完整。请帮忙从英语翻译这篇文章

GamepadGamepad API的接口,定义为一个独立的游戏手柄或其他控制器,允许访问如按钮按下,方位和id等信息。

一个Gamepad对象能以两种方式返回:通过gamepadgamepadconnectedgamepaddisconnected事件属性,或者获取Navigator.getGamepads()方法中返回的数组中的任意值。

属性

Gamepad.displayId 只读
返回VRDisplay.displayId of the associated VRDisplay — the VRDisplay that the gamepad is controlling the displayed scene of.
Gamepad.id 只读
A DOMString containing identifying information about the controller.
Gamepad.index 只读
An integer that is auto-incremented to be unique for each device currently connected to the system.
Gamepad.mapping 只读
A string indicating whether the browser has remapped the controls on the device to a known layout.
Gamepad.connected 只读
A boolean indicating whether the gamepad is still connected to the system.
Gamepad.buttons 只读
An array of gamepadButton objects representing the buttons present on the device.
Gamepad.axes 只读
An array representing the controls with axes present on the device (e.g. analog thumb sticks).
Gamepad.timestamp 只读
A DOMHighResTimeStamp representing the last time the data for this gamepad was updated.

例子

window.addEventListener("gamepadconnected", function(e) {
  console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
  e.gamepad.index, e.gamepad.id,
  e.gamepad.buttons.length, e.gamepad.axes.length);
});

规格

Specification Status Comment
Gamepad
Gamepad
Working Draft Initial defintion
Unknown
displayId
Unknown Defines the Gamepad.displayId property.

浏览器兼容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
General support 21.0 webkit
35.0
(Yes) 29.0 (29.0) 未实现 15.0 webkit
22.0
未实现
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
General support 未实现 ? 32.0 (32.0) 未实现 未实现 未实现

参考

文档标签和贡献者

 此页面的贡献者: lixuanh
 最后编辑者: lixuanh,