This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

axes

Summary

Array of values for all axes of the gamepad. Each entry in the array is a floating point value in the range -1.0 - 1.0, representing the axis position from the lowest value (-1.0) to the highest value (1.0).

Property of apis/gamepad/Gamepadapis/gamepad/Gamepad

Syntax

Note: This property is read-only.

var result = object.axes;

Return Value

Returns an object of type

array of doubles.

Examples

The Gamepad API provides a function, Navigator.getGamepads, that returns a list of all devices currently visible to the web page, as an array of Gamepad objects. When a gamepad is connected, this example reports its index, id, number of buttons, number of axes, and when the gamepad data was updated.

window.addEventListener("gamepadconnected", function(e) {
  var gp = navigator.getGamepads()[e.gamepad.index];
  console.log("Gamepad connected.");
  console.log("Gamepad index:", gp.index);
  console.log("Gamepad id:", gp.id);
  console.log("Gamepad buttons:", gp.buttons.length);
  console.log("Gamepad axes:", gp.axes.length);
  console.log("Gamepad last updated:", gp.timestamp);
});

Related specifications

W3C Gamepad Specification
W3C Working Draft

Attributions

  • Mozilla Developer Network cc-by-sa-small-wpd.svg: Article