mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
doc: Update gamepad.html
This commit is contained in:
parent
37ca48dc38
commit
dc4dc92dd0
@ -41,44 +41,50 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
screenWidth = 320
|
screenWidth = 640
|
||||||
screenHeight = 240
|
screenHeight = 480
|
||||||
)
|
)
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
// TODO: API to get the available, lowest ID
|
ids := ebiten.GamepadIDs()
|
||||||
const gamepadID = 0
|
axes := map[int][]string{}
|
||||||
axes := []string{}
|
pressedButtons := map[int][]string{}
|
||||||
pressedButtons := []string{}
|
|
||||||
|
|
||||||
maxAxis := ebiten.GamepadAxisNum(gamepadID)
|
for _, id := range ids {
|
||||||
for a := 0; a < maxAxis; a++ {
|
maxAxis := ebiten.GamepadAxisNum(id)
|
||||||
v := ebiten.GamepadAxis(gamepadID, a)
|
for a := 0; a < maxAxis; a++ {
|
||||||
axes = append(axes, fmt.Sprintf("%d: %0.6f", a, v))
|
v := ebiten.GamepadAxis(id, a)
|
||||||
}
|
axes[id] = append(axes[id], fmt.Sprintf("%d:%0.2f", a, v))
|
||||||
|
}
|
||||||
maxButton := ebiten.GamepadButton(ebiten.GamepadButtonNum(gamepadID))
|
maxButton := ebiten.GamepadButton(ebiten.GamepadButtonNum(id))
|
||||||
for b := ebiten.GamepadButton(gamepadID); b < maxButton; b++ {
|
for b := ebiten.GamepadButton(id); b < maxButton; b++ {
|
||||||
if ebiten.IsGamepadButtonPressed(gamepadID, b) {
|
if ebiten.IsGamepadButtonPressed(id, b) {
|
||||||
pressedButtons = append(pressedButtons, strconv.Itoa(int(b)))
|
pressedButtons[id] = append(pressedButtons[id], strconv.Itoa(int(b)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ebiten.IsRunningSlowly() {
|
if ebiten.IsRunningSlowly() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
str := `Gamepad
|
str := ""
|
||||||
Axes:
|
if len(ids) > 0 {
|
||||||
{{.Axes}}
|
for _, id := range ids {
|
||||||
Pressed Buttons: {{.Buttons}}`
|
str += fmt.Sprintf("Gamepad (ID: %d):\n", id)
|
||||||
str = strings.Replace(str, "{{.Axes}}", strings.Join(axes, "\n "), -1)
|
str += fmt.Sprintf(" Axes: %s\n", strings.Join(axes[id], ", "))
|
||||||
str = strings.Replace(str, "{{.Buttons}}", strings.Join(pressedButtons, ", "), -1)
|
str += fmt.Sprintf(" Buttons: %s\n", strings.Join(pressedButtons[id], ", "))
|
||||||
|
str += "\n"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
str = "Please connect your gamepad."
|
||||||
|
}
|
||||||
ebitenutil.DebugPrint(screen, str)
|
ebitenutil.DebugPrint(screen, str)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Gamepad (Ebiten Demo)"); err != nil {
|
if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Gamepad (Ebiten Demo)"); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user