I want to vibrate my device in one of my slider functionality, using cocos2d-x 3.2.
I followed some of reference links regarding this on the official forums but I'm still stumped.
Can anyone help me?
I want to vibrate my device in one of my slider functionality, using cocos2d-x 3.2.
I followed some of reference links regarding this on the official forums but I'm still stumped.
Can anyone help me?
After Searching a lot , Finally i am done with my Vibrate Function in Cocos2d-x 3.2 for android.
There is one Vibrator Class.
Vibrator.h
Vibrator.cpp
=> in AndroidManifest.xml : add below permission .
=> in src/org/cocos2dx/lib/Cocos2dxHelper.java file : add below 2 methods
first import => import android.os.Vibrator;
then , add these 2 methods
Now, Whenever we want to use Vibrate Function we just have to include this Vibrator Class & Simply Calling it as below .
For Disabling it,
in won't work in Tab as it does not having Vibrator in it .
There's supposed to be a working implementation of vibrate on iOS and Android on FenneX's github.
sourced from a forum post asking the same thing
Based on the code found in the forum post:
Classes/
folder where you just have the cpp function declared but not defined.proj.android/jni
, in a.cpp
file. I usedproj.android/jni/hellocpp/main.cpp
, which I believe is the default for a starter cocos2dxv3 project. In this method you call the method you've defined in your java, in this case it was defined as a static method on your Activity. The default was named `AppActivity.proj.android/AndroidManifest.xml
,<uses-permission android:name="android.permission.VIBRATE"/>
So, in one of your standard C++ headers in the
Classes/
folder, addand in the associated
.cpp
file, call it:In your
proj.android/AndroidManifest.xml
, you'll want to add that lineIn a cpp file the
jni
will deal with, sayproj.android/jni/hellocpp/main.cpp
, you'll need to define the connection between the Java and C++ by calling the Java method:finally, here's the
.java
file where the android call to vibrate is made. Mine wasproj.android/src/org/cocos2dx/cpp/AppActivity.java