mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
parent
edff1f0dd9
commit
d4b722eb06
@ -63,7 +63,7 @@ type UI interface {
|
|||||||
SetScreenTransparent(transparent bool)
|
SetScreenTransparent(transparent bool)
|
||||||
SetInitFocused(focused bool)
|
SetInitFocused(focused bool)
|
||||||
|
|
||||||
Vibrate(duration time.Duration, intensity float64)
|
Vibrate(duration time.Duration, magnitude float64)
|
||||||
|
|
||||||
Input() Input
|
Input() Input
|
||||||
Window() Window
|
Window() Window
|
||||||
|
@ -1625,6 +1625,6 @@ func (u *UserInterface) setOrigPos(x, y int) {
|
|||||||
u.origPosY = y
|
u.origPosY = y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, intensity float64) {
|
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
@ -653,8 +653,8 @@ func (u *UserInterface) SetInitFocused(focused bool) {
|
|||||||
u.initFocused = focused
|
u.initFocused = focused
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, intensity float64) {
|
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
||||||
// intensity is ignored.
|
// magnitude is ignored.
|
||||||
|
|
||||||
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))
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
//
|
//
|
||||||
// Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
|
// Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
// if (Build.VERSION.SDK_INT >= 26) {
|
// if (Build.VERSION.SDK_INT >= 26) {
|
||||||
// v.vibrate(VibrationEffect.createOneShot(milliseconds, intensity * 255))
|
// v.vibrate(VibrationEffect.createOneShot(milliseconds, magnitude * 255))
|
||||||
// } else {
|
// } else {
|
||||||
// v.vibrate(millisecond)
|
// v.vibrate(millisecond)
|
||||||
// }
|
// }
|
||||||
@ -40,7 +40,7 @@ import (
|
|||||||
//
|
//
|
||||||
// <uses-permission android:name="android.permission.VIBRATE"/>
|
// <uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
//
|
//
|
||||||
static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, int64_t milliseconds, double intensity) {
|
static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, int64_t milliseconds, double magnitude) {
|
||||||
JavaVM* vm = (JavaVM*)java_vm;
|
JavaVM* vm = (JavaVM*)java_vm;
|
||||||
JNIEnv* env = (JNIEnv*)jni_env;
|
JNIEnv* env = (JNIEnv*)jni_env;
|
||||||
jobject context = (jobject)ctx;
|
jobject context = (jobject)ctx;
|
||||||
@ -77,7 +77,7 @@ static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx,
|
|||||||
(*env)->CallStaticObjectMethod(
|
(*env)->CallStaticObjectMethod(
|
||||||
env, android_os_VibrationEffect,
|
env, android_os_VibrationEffect,
|
||||||
(*env)->GetStaticMethodID(env, android_os_VibrationEffect, "createOneShot", "(JI)Landroid/os/VibrationEffect;"),
|
(*env)->GetStaticMethodID(env, android_os_VibrationEffect, "createOneShot", "(JI)Landroid/os/VibrationEffect;"),
|
||||||
milliseconds, (int)(intensity * 255));
|
milliseconds, (int)(magnitude * 255));
|
||||||
|
|
||||||
(*env)->CallVoidMethod(
|
(*env)->CallVoidMethod(
|
||||||
env, vibrator,
|
env, vibrator,
|
||||||
@ -104,10 +104,10 @@ static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx,
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, intensity float64) {
|
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
||||||
_ = app.RunOnJVM(func(vm, env, ctx uintptr) error {
|
_ = app.RunOnJVM(func(vm, env, ctx uintptr) error {
|
||||||
// TODO: This might be crash when this is called from init(). How can we detect this?
|
// TODO: This might be crash when this is called from init(). How can we detect this?
|
||||||
C.vibrateOneShot(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), C.int64_t(duration/time.Millisecond), C.double(intensity))
|
C.vibrateOneShot(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), C.int64_t(duration/time.Millisecond), C.double(magnitude))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,6 @@ package mobile
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -103,9 +102,9 @@ import (
|
|||||||
|
|
||||||
var vibrationM sync.Mutex
|
var vibrationM sync.Mutex
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, intensity float64) {
|
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
||||||
vibrationM.Lock()
|
vibrationM.Lock()
|
||||||
defer vibrationM.Unlock()
|
defer vibrationM.Unlock()
|
||||||
|
|
||||||
C.vibrate(C.double(float64(duration)/float64(time.Second)), C.double(intensity))
|
C.vibrate(C.double(float64(duration)/float64(time.Second)), C.double(magnitude))
|
||||||
}
|
}
|
||||||
|
12
vibrate.go
12
vibrate.go
@ -23,23 +23,23 @@ type VibrateOptions struct {
|
|||||||
// Duration is the time duration of the effect.
|
// Duration is the time duration of the effect.
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
|
|
||||||
// Intensity is the strength of the device vibration.
|
// Magnitude is the strength of the device vibration.
|
||||||
// The value is in between 0 and 1.
|
// The value is in between 0 and 1.
|
||||||
Intensity float64
|
Magnitude float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vibrate vibrates the device with the specified options.
|
// Vibrate vibrates the device with the specified options.
|
||||||
//
|
//
|
||||||
// Vibrate works on mobiles and browsers.
|
// Vibrate works on mobiles and browsers.
|
||||||
//
|
//
|
||||||
// On browsers, Intensity in the options is ignored.
|
// On browsers, Magnitude in the options is ignored.
|
||||||
//
|
//
|
||||||
// On Android, this line is required in the manifest setting to use Vibrate:
|
// On Android, this line is required in the manifest setting to use Vibrate:
|
||||||
//
|
//
|
||||||
// <uses-permission android:name="android.permission.VIBRATE"/>
|
// <uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
//
|
//
|
||||||
// On Android, Intensity in the options is recognized only when the API Level is 26 or newer.
|
// On Android, Magnitude in the options is recognized only when the API Level is 26 or newer.
|
||||||
// Otherwise, Intensity is ignored.
|
// Otherwise, Magnitude is ignored.
|
||||||
//
|
//
|
||||||
// On iOS, CoreHaptics.framework is required to use Vibrate.
|
// On iOS, CoreHaptics.framework is required to use Vibrate.
|
||||||
//
|
//
|
||||||
@ -48,7 +48,7 @@ type VibrateOptions struct {
|
|||||||
//
|
//
|
||||||
// Vibrate is concurrent-safe.
|
// Vibrate is concurrent-safe.
|
||||||
func Vibrate(options *VibrateOptions) {
|
func Vibrate(options *VibrateOptions) {
|
||||||
uiDriver().Vibrate(options.Duration, options.Intensity)
|
uiDriver().Vibrate(options.Duration, options.Magnitude)
|
||||||
}
|
}
|
||||||
|
|
||||||
// VibrateGamepadOptions represents the options for gamepad vibration.
|
// VibrateGamepadOptions represents the options for gamepad vibration.
|
||||||
|
Loading…
Reference in New Issue
Block a user