mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: Vibrate takes time durations instead of the options
Android and browsers can specify only a time duration for vibration. VibrateOptions is renamed to GamepadVibrateOptions for gamepads. Updates #1452
This commit is contained in:
parent
f96d0a97a8
commit
7c6f2fd799
@ -39,11 +39,7 @@ func (g *Game) Update() error {
|
|||||||
g.touchIDs = g.touchIDs[:0]
|
g.touchIDs = g.touchIDs[:0]
|
||||||
g.touchIDs = inpututil.AppendJustPressedTouchIDs(g.touchIDs)
|
g.touchIDs = inpututil.AppendJustPressedTouchIDs(g.touchIDs)
|
||||||
if len(g.touchIDs) > 0 {
|
if len(g.touchIDs) > 0 {
|
||||||
op := &ebiten.VibrateOptions{
|
ebiten.Vibrate(200 * time.Millisecond)
|
||||||
Duration: 200 * time.Millisecond,
|
|
||||||
StrongMagnitude: 1,
|
|
||||||
}
|
|
||||||
ebiten.Vibrate(op)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -63,7 +63,7 @@ type UI interface {
|
|||||||
SetScreenTransparent(transparent bool)
|
SetScreenTransparent(transparent bool)
|
||||||
SetInitFocused(focused bool)
|
SetInitFocused(focused bool)
|
||||||
|
|
||||||
Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64)
|
Vibrate(duration time.Duration)
|
||||||
|
|
||||||
Input() Input
|
Input() Input
|
||||||
Window() Window
|
Window() Window
|
||||||
|
@ -1686,6 +1686,6 @@ func (u *UserInterface) setOrigPos(x, y int) {
|
|||||||
u.origPosY = y
|
u.origPosY = y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
|
func (u *UserInterface) Vibrate(duration time.Duration) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,7 @@ func (u *UserInterface) SetInitFocused(focused bool) {
|
|||||||
u.initFocused = focused
|
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() {
|
if js.Global().Get("navigator").Get("vibrate").Truthy() {
|
||||||
js.Global().Get("navigator").Call("vibrate", float64(duration/time.Millisecond))
|
js.Global().Get("navigator").Call("vibrate", float64(duration/time.Millisecond))
|
||||||
}
|
}
|
||||||
|
@ -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)
|
// TODO: Implement this (#1452)
|
||||||
}
|
}
|
||||||
|
24
vibrate.go
24
vibrate.go
@ -18,8 +18,18 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VibrateOptions represents the options to vibrate a device.
|
// Vibrate vibrates the device.
|
||||||
type VibrateOptions struct {
|
//
|
||||||
|
// 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 is the time duration of the effect.
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
|
|
||||||
@ -32,12 +42,4 @@ type VibrateOptions struct {
|
|||||||
WeakMagnitude float64
|
WeakMagnitude float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vibrate vibrates the device.
|
// TODO: Add a function VibrateGamepad.
|
||||||
//
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user