From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/gamepad_api/index.html | 100 +++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 files/zh-cn/web/api/gamepad_api/index.html (limited to 'files/zh-cn/web/api/gamepad_api/index.html') diff --git a/files/zh-cn/web/api/gamepad_api/index.html b/files/zh-cn/web/api/gamepad_api/index.html new file mode 100644 index 0000000000..e8f55730a3 --- /dev/null +++ b/files/zh-cn/web/api/gamepad_api/index.html @@ -0,0 +1,100 @@ +--- +title: Gamepad API +slug: Web/API/Gamepad_API +tags: + - 实验性 + - 手柄 + - 控制器 + - 概述 + - 游戏 +translation_of: Web/API/Gamepad_API +--- +

{{DefaultAPISidebar("Gamepad API")}}{{SeeCompatTable}}

+ +

 

+ +

Gamepad API 可以给予开发者一种简单、统一的方式来识别并响应游戏控制器(手柄)。其中包含了三个接口、两个事件、一个特殊函数,用来响应控制器的连接与断开、获取其他关于控制器的信息以及识别当前是哪个按键或是哪个控制器被按下了。

+ +

接口

+ +
+
{{domxref("Gamepad")}}
+
表示已连接的游戏控制器。
+
{{domxref("GamepadButton")}}
+
表示已连接手柄上的一个按键。
+
{{domxref("GamepadEvent")}}
+
表示与控制器相关的事件的事件对象。
+
+ +

实验性 Gamepad 扩展

+ +
+
{{domxref("GamepadHapticActuator")}}
+
表示控制器中的硬件,用于向用户提供触觉反馈(如果可用)最常见的是振动硬件。
+
{{domxref("GamepadPose")}}
+
表示控制器的位置方向(例如, 在3D 空间中的位置和方向)于 WebVR 控制器中。
+
+ +

另请参阅  Gamepad 接口扩展,来获取上方的功能的相关信息。

+ +

其他接口扩展

+ + + +
+
{{domxref("Navigator.getGamepads()")}}
+
于 {{domxref("Navigator")}} 对象中的一个扩展。会返回一个 名为{{domxref("Gamepad")}} 的数组对象,其中每个数组元素对应一个已连接的控制器。
+
+ +

Window 事件

+ +
+
{{domxref("Window.ongamepadconnected")}}
+
表示当控制器连接时(当{{event('gamepadconnected')}} 事件触发时)运行的处理程序。
+
{{domxref("Window.ongamepaddisconnected")}}
+
表示当控制器断开连接时(当{{event('gamepaddisconnected')}} 事件触发时)运行的处理程序。
+
+ +

教程与指南

+ + + +

规范

+ + + + + + + + + + + + + + + + + + + +
规范状态备注
{{SpecName("GamepadExtensions")}}{{Spec2("GamepadExtensions")}}Defines the {{anch("Experimental Gamepad extensions")}}.
{{SpecName("Gamepad", "", "The Gamepad API specification")}}{{Spec2("Gamepad")}}Initial definition
+ +

浏览器兼容性

+ + + +

{{Compat("api.Gamepad")}}

+ +

另请参阅

+ + -- cgit v1.2.3-54-g00ecf