Add docs for gamepad API (I checked it worked on Chrome)

This commit is contained in:
Hajime Hoshi 2015-01-12 14:55:28 +09:00
parent 8987f7a645
commit 02dbeef1b9
4 changed files with 29 additions and 7 deletions

View File

@ -76,6 +76,14 @@ pre {
<p>NOTE: <code>file://</code> URL may not work with Ebiten. Execute your game on a HTTP server.</p>
<h2>Change Log</h2>
<h3>2015-??-??</h3>
<ul>
<li>v1.2.0-rc1 released.
<ul>
<li>Support for gamepads</li>
</ul>
</li>
</ul>
<h3>2015-01-10</h3>
<ul>
<li>v1.1.0-rc1 released.

View File

@ -36,20 +36,34 @@ func IsMouseButtonPressed(mouseButton MouseButton) bool {
return ui.IsMouseButtonPressed(ui.MouseButton(mouseButton))
}
// TODO: docs
// GamepadAxisNum returns the number of axes of the gamepad.
//
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
// To use this API, browsers might require rebooting the browser.
func GamepadAxisNum(id int) int {
return ui.GamepadAxisNum(id)
}
// GamepadAxis returns the float value [-1.0 - 1.0] of the axis.
//
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
// To use this API, browsers might require rebooting the browser.
func GamepadAxis(id int, axis int) float64 {
return ui.GamepadAxis(id, axis)
}
// GamepadButtonNum returns the number of the buttons of the gamepad.
//
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
// To use this API, browsers might require rebooting the browser.
func GamepadButtonNum(id int) int {
return ui.GamepadButtonNum(id)
}
// IsGamepadButtonPressed returns the boolean indicating the buttons is pressed or not.
//
// NOTE: Gamepad API is available only on desktops, Chrome and Firefox.
// To use this API, browsers might require rebooting the browser.
func IsGamepadButtonPressed(id int, button GamepadButton) bool {
return ui.IsGamepadButtonPressed(id, ui.GamepadButton(button))
}

View File

@ -65,7 +65,11 @@ func (i *input) mouseMove(x, y int) {
}
func (i *input) updateGamepads() {
gamepads := js.Global.Get("navigator").Call("getGamepads")
nav := js.Global.Get("navigator")
if nav.Get("getGamepads") == js.Undefined {
return
}
gamepads := nav.Call("getGamepads")
l := gamepads.Get("length").Int()
for id := 0; id < l; id++ {
gamepad := gamepads.Index(id)

View File

@ -158,10 +158,6 @@ func init() {
// Gamepad
window.Call("addEventListener", "gamepadconnected", func(e js.Object) {
print(e)
})
window.Call("addEventListener", "gamepaddisconnected", func(e js.Object) {
print(e)
})
}