Hi All,
How do we vibrate device in Cocos Creator?
Thanks in advance!
Hi All,
How do we vibrate device in Cocos Creator?
Thanks in advance!
Perhaps these can point you in the right direction
Thanks for your reply.
I saw it but, its for calling static methods?
So, we have to write vibration codes in native and expose it as a static method to be called by JS?
How could we miss such an important feature for games in a popular game engine! Or Did i miss anything?
I think this is a critical problem for such an engine like Creator.
No example code given although too many questions raised.
Waiting for the official answer from admins.
I don’t know if the cocos accept java. i think yes. I’m new on cocos, but if you want vibrate, you need to use tha code on your font. you call some java library. in your source …
import android.os.Vibrator;
import android.os.Vibrator;
...
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
//deprecated in API 26
// If you want to vibrate indefinely put 0.
v.vibrate(500);
}
//If you want a diffrent vibration you can use If with a VibrationEffect (createOneShot){}
//(Acc therms)
<uses-permission android:name="android.permission.VIBRATE"/>