To retrieve information about the mutiple gamepads, such as axis and button values, use navigator.getGamepads() method:
var gamepads = navigator.getGamepads();
if(!gamepads){
return;
}
for(var i = 0; i < gamepads.length(); i++){
var gp = gamepads[i];
if(!gp){
continue;
}
console.log(gp.axes[0]); // axes[0]
console.log(gp.buttons[0]); // buttons[0]
...
}
To make Gamepad have a vibration effect, use Gamepad.vibrationActuator.playEffect method:
for(var i = 0 ; i < gamepads.length ; i++){
var gp = gamepads[i];
if(!gp){
continue;
}
if (gp.buttons[0]) {//Button A is pressed, start vibration
if(gp.vibrationActuator){
gp.vibrationActuator.playEffect("dual-rumble", {duration: 50, strongMagnitude: 1.0, weakMagnitude: 1.0});//duration: 50ms
}
}
}
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.