このインタフェースは、ゲームパッドやその他のコントローラーの各ボタンを定義します。このインタフェースによって、コントローラー上で使用できるボタンの状態を確認することができます。
GamepadButton オブジェクトは、Gamepad インタフェースの buttons プロパティから取得できます。
注釈: これは Firefox Gecko 28 以降の場合の説明であり、Chrome と以前の Firefox のバージョンでは、浮動小数点数の配列が返されます。
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); };
[当のボタンにはタッチを検出する能力はある]ならば:
[当のボタンにはアナログ値を報告する能力はある]ならば:
これ°の pressed 属性が返す値を返す
表示内容: |
表示内容: |