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