You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.1 KiB
57 lines
1.1 KiB
import { MiniGamePlatform } from '../platform/MiniGamePlatform';
|
|
|
|
/**
|
|
* 设备震动相关
|
|
*/
|
|
export default class Vibrate {
|
|
/**开关 */
|
|
public static IsEnable = true;
|
|
/**是否开始震动 */
|
|
public static IsStartVibrate = false;
|
|
|
|
/**当前平台 API */
|
|
public static get Pf() {
|
|
MiniGamePlatform.init();
|
|
return MiniGamePlatform.pf;
|
|
}
|
|
|
|
/**
|
|
* 短震动
|
|
*/
|
|
public static vibrateShort(): void {
|
|
if (!this.IsEnable) return;
|
|
this.Pf?.vibrateShort?.({ type: 'medium' });
|
|
}
|
|
|
|
/**
|
|
* 长震动
|
|
*/
|
|
public static vibrateLong(): void {
|
|
if (!this.IsEnable) return;
|
|
this.Pf?.vibrateLong?.();
|
|
}
|
|
|
|
/**
|
|
* 开始持续震动
|
|
*/
|
|
public static startVibrate() {
|
|
this.IsStartVibrate = true;
|
|
this.loopVibrate();
|
|
}
|
|
|
|
/**
|
|
* 结束持续震动
|
|
*/
|
|
public static stopVibrate() {
|
|
this.IsStartVibrate = false;
|
|
}
|
|
|
|
private static loopVibrate() {
|
|
this.vibrateShort();
|
|
setTimeout(() => {
|
|
if (this.IsStartVibrate) {
|
|
this.loopVibrate();
|
|
}
|
|
}, 30);
|
|
}
|
|
}
|
|
|