Chrome上的HTML5游戏手柄API [英] HTML5 Gamepad API on Chrome

查看:334
本文介绍了Chrome上的HTML5游戏手柄API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Chrome(版本19.0.1084.46).我在chrome://flags中启用了Gamepad API.我插入了一些游戏手柄,但是navigator.webkitGamepads始终是长度为4的数组,只包含未定义的

I'm using Chrome (Version 19.0.1084.46). I enabled the Gamepad API in chrome://flags. I plugged in some game pads, but navigator.webkitGamepads is always an array of length 4 containing only undefined.

navigator.webkitGamepads
GamepadList
  0: undefined
  1: undefined
  2: undefined
  3: undefined
  length: 4
  __proto__: GamepadList

我需要做些什么才能使用游戏手柄进行测试?如果那很重要,我就在Ubuntu Linux上.

What do I need to do to test out using gamepads? I'm on Ubuntu Linux if that matters.

推荐答案

我也遇到了麻烦(在带有Chrome 21.0.1163.0开发人员的Ubuntu 10.04上).我从关于铬的讨论中发现了这个问题:

I was having trouble with this as well (on Ubuntu 10.04 with Chrome 21.0.1163.0 dev). I ran across this from a thread on chromium-discussions:

请注意,您需要先在游戏板上按一个面部按钮,然后才能显示数据 将可用.这是由于指纹问题.

Note that you need to press a face button on the gamepad before data will be available. This is due to fingerprinting concerns.

我写了一个快速测试页,如果您在刷新鼠标左键的同时按住控制器按钮,似乎可以正常工作页.我正在使用带xboxdrv驱动程序的Gamestop品牌的Xbox 360有线控制器.

I wrote a quick test page that seems to work if you hold a controller button down while refreshing the page. I'm using a Gamestop-branded Xbox 360 wired controller with the xboxdrv driver.

还有另一件事要注意-Chrome将这些Gamepad对象视为控制器状态的快照.因此,如果您传递实际的Gamepad对象,您将永远不会获得更新的信息. Chrome似乎仅在调用navigator.webkitGamepads[x] getter时轮询控制器(请参见我的测试页中的第23行).

Also, one other important thing to note - Chrome treats these Gamepad objects like snapshots of the controller state. So if you pass around the actual Gamepad object, you'll never get updated information. Chrome seems to only poll the controller when you call the navigator.webkitGamepads[x] getter (see line 23 in my test page).

这篇关于Chrome上的HTML5游戏手柄API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆