Gamepad - Web APIs 编辑

The Gamepad interface of the Gamepad API defines an individual gamepad or other controller, allowing access to information such as button presses, axis positions, and id.

A Gamepad object can be returned in one of two ways: via the gamepad property of the gamepadconnected and gamepaddisconnected events, or by grabbing any position in the array returned by the Navigator.getGamepads() method.

Properties

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

Experimental extensions to Gamepad

The following interfaces are defined in the Gamepad Extensions specification, and provide access to experimental features like haptic feedback and WebVR controller pose information.

Gamepad.hand Read only
An enum defining what hand the controller is being held in, or is most likely to be held in.
Gamepad.hapticActuators Read only
An array containing GamepadHapticActuator objects, each of which represents haptic feedback hardware available on the controller.
Gamepad.pose Read only
A GamepadPose object representing the pose information associated with a WebVR controller (e.g. its position and orientation in 3D space).

Example

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);
});

Specifications

SpecificationStatusComment
Gamepad
The definition of 'Gamepad' in that specification.
Working DraftInitial definition
WebVR 1.1
The definition of 'displayId' in that specification.
DraftDefines the Gamepad.displayId property.
Gamepad Extensions
The definition of 'Gamepad extensions' in that specification.
Editor's DraftDefines the Experimental extensions to Gamepad

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:115 次

字数:6506

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文