Right, I decided I wanted to add vibration to my game so i decided to write some methods using jni to invoke the android sdk api and places them into cocos2dDenshin..
For anyone who wants to try it here’s what to do.
I edited 7 files in total. Here are the instructions of what to do:
- You must edit the AndroidManifest.xml file and add the following line:
This will allow your app to use vibration. So for example
<?xml version="1.0" encoding="utf-8"?>
- I modified 6 other files which you can replace from the zip. Here’s where each goes:
2.1 Both Cocos2dxActivity.java and Cocos2dxsound.java are generated in your project directory everytime you run the create-android-project.bat file. You must place Cocos2dxActivity.java and Cocos2dxsound.java and into 2dx\lib
The modifications I added were adding 3 methods; vibrate(long time), vibrateWithPattern(long pattern, int repeat), cancelVibrate().
2.2 Next two files are SimpleAudioEngineJni.h and SimpleAudioEngineJni.cpp. These two files go into
The modifications I added were adding and delcaring 3 methods; vibrateJNI(long long time), vibrateWithPatternJNI(long long pattern, int repeat), cancelVibrateJNI().
2.3 The next file is SimpleAudioEngine.h. This goes into
The modifications I added were declaring 3 methods; vibrate(long long time), vibrateWithPattern(long long pattern, int repeat), cancelVibrate()
2.4 The last file is SimpleAudioEngine.cpp. This goes into
The modifications I added were adding 3 methods; vibrate(long long time), vibrateWithPattern(long long pattern, int repeat), cancelVibrate().
to add a vibration all you need to do is call the method like so: CocosDenshion::SimpleAudioEngine::sharedEngine()->vibrate(time);
the variable time is a long type integer and is a measurement of milliseconds.
the methods were created with intention of keeping the same structure of the vibrate methods from the android sdk: http://developer.android.com/reference/android/os/Vibrator.html.