diff --git a/examples/vibrate/main.go b/examples/vibrate/main.go index 1cd749461..8b6913b17 100644 --- a/examples/vibrate/main.go +++ b/examples/vibrate/main.go @@ -39,11 +39,7 @@ func (g *Game) Update() error { g.touchIDs = g.touchIDs[:0] g.touchIDs = inpututil.AppendJustPressedTouchIDs(g.touchIDs) if len(g.touchIDs) > 0 { - op := &ebiten.VibrateOptions{ - Duration: 200 * time.Millisecond, - StrongMagnitude: 1, - } - ebiten.Vibrate(op) + ebiten.Vibrate(200 * time.Millisecond) } return nil diff --git a/internal/driver/ui.go b/internal/driver/ui.go index a8ebf6ac0..9fcab0cd7 100644 --- a/internal/driver/ui.go +++ b/internal/driver/ui.go @@ -63,7 +63,7 @@ type UI interface { SetScreenTransparent(transparent bool) SetInitFocused(focused bool) - Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) + Vibrate(duration time.Duration) Input() Input Window() Window diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 823f25275..97ba24de7 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -1686,6 +1686,6 @@ func (u *UserInterface) setOrigPos(x, y int) { u.origPosY = y } -func (u *UserInterface) Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) { +func (u *UserInterface) Vibrate(duration time.Duration) { // Do nothing. } diff --git a/internal/uidriver/js/ui_js.go b/internal/uidriver/js/ui_js.go index 196888c58..409ddf895 100644 --- a/internal/uidriver/js/ui_js.go +++ b/internal/uidriver/js/ui_js.go @@ -648,7 +648,7 @@ func (u *UserInterface) SetInitFocused(focused bool) { u.initFocused = focused } -func (u *UserInterface) Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) { +func (u *UserInterface) Vibrate(duration time.Duration) { if js.Global().Get("navigator").Get("vibrate").Truthy() { js.Global().Get("navigator").Call("vibrate", float64(duration/time.Millisecond)) } diff --git a/internal/uidriver/mobile/ui.go b/internal/uidriver/mobile/ui.go index cbea3a482..21f85b58b 100644 --- a/internal/uidriver/mobile/ui.go +++ b/internal/uidriver/mobile/ui.go @@ -494,6 +494,6 @@ func (u *UserInterface) ScheduleFrame() { } } -func (u *UserInterface) Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) { +func (u *UserInterface) Vibrate(duration time.Duration) { // TODO: Implement this (#1452) } diff --git a/vibrate.go b/vibrate.go index 277012e49..025b264bd 100644 --- a/vibrate.go +++ b/vibrate.go @@ -18,8 +18,18 @@ import ( "time" ) -// VibrateOptions represents the options to vibrate a device. -type VibrateOptions struct { +// Vibrate vibrates the device. +// +// Vibrate works on mobiles and browsers. +// On browsers, StrongManitude and WeakMagnitude might be ignored. +// +// Vibrate is concurrent-safe. +func Vibrate(duration time.Duration) { + uiDriver().Vibrate(duration) +} + +// GamepadVibrateOptions represents the options to vibrate a gamepad. +type GamepadVibrateOptions struct { // Duration is the time duration of the effect. Duration time.Duration @@ -32,12 +42,4 @@ type VibrateOptions struct { WeakMagnitude float64 } -// Vibrate vibrates the device. -// -// Vibrate works on mobiles and browsers. -// On browsers, StrongManitude and WeakMagnitude might be ignored. -// -// Vibrate is concurrent-safe. -func Vibrate(options *VibrateOptions) { - uiDriver().Vibrate(options.Duration, options.StrongMagnitude, options.WeakMagnitude) -} +// TODO: Add a function VibrateGamepad.