From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/ru/web/api/gamepadbutton/index.html | 85 +++++++++++++++++++++++ files/ru/web/api/gamepadbutton/pressed/index.html | 52 ++++++++++++++ files/ru/web/api/gamepadbutton/value/index.html | 51 ++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 files/ru/web/api/gamepadbutton/index.html create mode 100644 files/ru/web/api/gamepadbutton/pressed/index.html create mode 100644 files/ru/web/api/gamepadbutton/value/index.html (limited to 'files/ru/web/api/gamepadbutton') diff --git a/files/ru/web/api/gamepadbutton/index.html b/files/ru/web/api/gamepadbutton/index.html new file mode 100644 index 0000000000..c119ee2401 --- /dev/null +++ b/files/ru/web/api/gamepadbutton/index.html @@ -0,0 +1,85 @@ +--- +title: GamepadButton +slug: Web/API/GamepadButton +translation_of: Web/API/GamepadButton +--- +
{{APIRef("Gamepad API")}}
+ +
Интерфейс GamepadButton определяет отдельную кнопку геймпада или другого контроллера, позволяя получить доступ к текущему состоянию различных типов кнопок, доступных на устройстве
+ +

Объект GamepadButton возвращается путем получения любого элемента в массиве buttons, который является свойством интерфейса {{domxref("Gamepad")}}.

+ +
+

Note: Это работает только в  Firefox Gecko 28 и выше;  Chrome и более ранние версии  Firefox по-прежнему возвращают массив чисел с плавающей точкой

+
+ +

Свойства

+ +
+
{{domxref("GamepadButton.value")}} {{readonlyInline}}
+
Значение с плавающей точкой, указывающее на текущее состояние аналоговых кнопок, таких как триггеры на многих современных геймпадах. Значение нормализованно к диапазону 0.0-1.0, где 0.0 означает, что клавиша не нажата совсем, 1.0 - нажата полностью.
+
{{domxref("GamepadButton.pressed")}} {{readonlyInline}}
+
Значение {{domxref("Boolean")}} указывает, нажата ли кнопка (true) или не нажата (false).
+
+ +

Пример

+ +

Приведенный код взят из моего (автора статьи) демо Gamepad API button (вы можете  Посмотреть демо, и посмотреть исходники на GitHub). Важно — в Chrome {{domxref("Navigator.getGamepads")}} неободимо установить префикс webkit, и значения кнопки будут представлять из себя массив дробных чисел, тогда как в  Firefox {{domxref("Navigator.getGamepads")}} нет необходимости устанавливать префикс, и значения будут представлять собой массив  объектов {{domxref("GamepadButton")}}; Свойство {{domxref("GamepadButton.value")}} или {{domxref("GamepadButton.pressed")}} необходимо для получения состояния кнопки, в зависимости от от типа кнопки. В данном простом примере обрабатывается оба вида кнопок.

+ +
function gameLoop() {
+  if(navigator.webkitGetGamepads) {
+    var gp = navigator.webkitGetGamepads()[0];
+
+    if(gp.buttons[0] == 1) {
+      b--;
+    } else if(gp.buttons[1] == 1) {
+      a++;
+    } else if(gp.buttons[2] == 1) {
+      b++;
+    } else if(gp.buttons[3] == 1) {
+      a--;
+    }
+  } else {
+    var gp = navigator.getGamepads()[0];
+
+    if(gp.buttons[0].value > 0 || gp.buttons[0].pressed == true) {
+      b--;
+    } else if(gp.buttons[1].value > 0 || gp.buttons[1].pressed == true) {
+      a++;
+    } else if(gp.buttons[2].value > 0 || gp.buttons[2].pressed == true) {
+      b++;
+    } else if(gp.buttons[3].value > 0 || gp.buttons[3].pressed == true) {
+      a--;
+    }
+  }
+
+  ball.style.left = a*2 + "px";
+  ball.style.top = b*2 + "px";
+
+  var start = window.requestAnimationFrame(gameLoop);
+};
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("Gamepad", "#gamepadbutton-interface", "GamepadButton")}}{{Spec2("Gamepad")}}Initial definition
+ +

Browser compatibility

+ +

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

+ +

См. также

+ +

Using the Gamepad API

diff --git a/files/ru/web/api/gamepadbutton/pressed/index.html b/files/ru/web/api/gamepadbutton/pressed/index.html new file mode 100644 index 0000000000..5222968bcc --- /dev/null +++ b/files/ru/web/api/gamepadbutton/pressed/index.html @@ -0,0 +1,52 @@ +--- +title: GamepadButton.pressed +slug: Web/API/GamepadButton/pressed +translation_of: Web/API/GamepadButton/pressed +--- +

{{APIRef("Gamepad API")}}

+ +

Свойство GamepadButton.pressed интерфейса {{domxref("GamepadButton")}} возвращает boolean, указыващий, нажата ли текущая кнопка (true), или нет (false).

+ +

Синтакс

+ +
var isPressed = navigator.getGamepads()[0].pressed;
+
+ +

Пример

+ +
var gp = navigator.getGamepads()[0]; // Get the first gamepad object
+
+if(gp.buttons[0].pressed == true) {
+  // respond to button being pressed
+}
+ +

Значение

+ +

 {{domxref("boolean")}}.

+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("Gamepad", "#dom-gamepadbutton-pressed", "GamepadButton.pressed")}}{{Spec2("Gamepad")}}Initial definition
+ +

Browser compatibility

+ +

{{Compat("api.GamepadButton.pressed")}}

+ +

See also

+ + diff --git a/files/ru/web/api/gamepadbutton/value/index.html b/files/ru/web/api/gamepadbutton/value/index.html new file mode 100644 index 0000000000..a1ccad261f --- /dev/null +++ b/files/ru/web/api/gamepadbutton/value/index.html @@ -0,0 +1,51 @@ +--- +title: GamepadButton.value +slug: Web/API/GamepadButton/value +translation_of: Web/API/GamepadButton/value +--- +

{{APIRef("Gamepad API")}}

+ +

Свойство GamepadButton.value  интерфейса {{domxref("GamepadButton")}} возвращает состояние аналоговой клавиши геймпада, такой, как, например триггеры. 

+ +

Пердставляет собой дробное число в диапазоне  0.01.0,  где 0.0 показывает, что кнопка не нажата, а 1.0 - что нажата полностью.

+ +

Синтаксис

+ +
    readonly    attribute double  value;
+ +

Пример

+ +
var gp = navigator.getGamepads()[0];
+
+if(gp.buttons[0].value > 0) {
+  // respond to analog button being pressed in
+} 
+ +

Значение

+ +

 {{domxref("double")}}.

+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("Gamepad", "#dom-gamepadbutton-value", "GamepadButton.value")}}{{Spec2("Gamepad")}}Initial definition
+ +

Browser compatibility

+ +

{{Compat("api.GamepadButton.value")}}

+ +

См. также

+ +

Using the Gamepad API

-- cgit v1.2.3-54-g00ecf