Using Gamepads in Google Dart

I am looking for code examples for the Gamepad API for Google Dart .

I tried to rely directly on the API and tried to write an instance for it.

//Gamepad Example: Gamepad g = new Gamepad(); g.id.toString(); // This doesn't seem to return anything... 

If anyone has some code examples for this, that would be fantastic!

+3
google-chrome dart
source share
2 answers

I tried this and it worked for me:

 import "dart:html"; main(){ window.animationFrame.then(runAnimation); } runAnimation(timestamp){ var gamepads = window.navigator.getGamepads(); for (var pad in gamepads) { if(pad != null){ querySelector("#buttons").setInnerHtml("${pad.buttons.join(" ")}</br>${pad.axes.join(" ")}"); } } window.requestAnimationFrame(runAnimation); } 
+3
source share

I don't have a gamepad to try, but

 Gamepad g = new Gamepad(); 

does not work because Gamepade does not have an open constructor.
Try

 var gp = window.navigator.getGamepads(); //or // haven't tried because I don't know how to provoke this event without a gamepad window.on['gamepadconnected'].listen((e) { var gamepad = e.gamepad; }); 

instead of this.
I get an empty list, so I can not learn more.

see also:
- https://developer.mozilla.org/en-US/docs/Web/Guide/API/Gamepad
- https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html

+2
source share

All Articles