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/ja/web/api/gamepadbutton/index.html | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 files/ja/web/api/gamepadbutton/index.html (limited to 'files/ja/web/api/gamepadbutton') diff --git a/files/ja/web/api/gamepadbutton/index.html b/files/ja/web/api/gamepadbutton/index.html new file mode 100644 index 0000000000..e3d77c59c3 --- /dev/null +++ b/files/ja/web/api/gamepadbutton/index.html @@ -0,0 +1,92 @@ +--- +title: GamepadButton +slug: Web/API/GamepadButton +tags: + - API + - Gamepad API + - Games + - NeedsBufferSpecLink + - NeedsMarkupWork + - Référence(2) +translation_of: Web/API/GamepadButton +--- +
{{APIRef("Gamepad API")}}
+ +

GamepadButton インタフェースはゲームパッドやその他のコントローラーの各ボタンを定義します。このインタフェースによって、コントローラー上で使用できるボタンの状態を確認することができます。

+ +

GamepadButtonオブジェクトは、{{domxref("Gamepad")}}インタフェースのbuttons プロパティから取得できます。

+ +
+

注釈: これはFirefox Gecko 28以降の場合の説明であり、Chrome と以前のFirefoxのバージョンでは、浮動小数点数の配列が返されます。

+
+ +

プロパティ

+ +
+
{{domxref("GamepadButton.value")}} {{readonlyInline}}
+
多くのモダンなゲームパッドにあるトリガーなどのアナログボタンの現在の状態を示す浮動小数点数です。この値は0.0から1.0までの値に正規化されており、0.0はボタンが押されていない状態で、1.0はボタンが完全に押されている状態を示します。
+
{{domxref("GamepadButton.pressed")}} {{readonlyInline}}
+
ボタンが押されているかどうかを示すboolean型の値です。ボタンが押されている場合はtrue、押されていない場合はfalseになります。
+
+ +

+ +

次のコードは、Gamepad API ボタンのデモです。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 = rAF(gameLoop);
+};
+ +

仕様

+ + + + + + + + + + + + + + +
仕様状態コメント
{{SpecName("Gamepad", "#gamepadbutton-interface", "GamepadButton")}}{{Spec2("Gamepad")}}初版
+ +

ブラウザ互換性

+ +

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

+ +

関連項目

+ +

Gamepad API の利用

-- cgit v1.2.3-54-g00ecf