Well i’ve searched some of the posts and most of them are very old
and some might not be working also…!!
So, here what i want to ask
I don’t seem cocos2d-x to have vibration to implement in games
I don’t know the cause, why they are not implementing this … !!
as this issue was raised in the late 2011 itself
But can’t wait for that…
This post might be working, but it’s for a very older version of cocos2d-x
also… i dont understand this post much
I use android 19 ndk r9d cocos2d-x 3.2
Can anyone give me a detailed view that how can i have vibration in my game ??
any help is greatly appreciated.
I implemented that on Android, it’s rather straightforward when you know JNI. You can see the implementation on my framework: https://github.com/FenneX/FenneX
The header is in projects/Classes/FenneX/NativeWrappers/NativeUtility.h
There is a .cpp file in projects/proj.android/jni/NativeUtility.cpp for the Android implementation
There is .java file in projects/proj.android/java/src/com/fennex/modules/NativeUtility.java
But there are a lot of limits that make vibration not really useful:
all tablets I tried don’t have a vibrator, so if it is a required feature you won’t be on tablets
there is a small delay before the device actually vibrate, which makes precise vibration a bit hard to do
The framework is for cocos2d-x 2.2, but those particular files work for v3.2, though you may have deprecated warnings.
i will dive into the code directly, and not the problem with the deprecation issues.
i will handle it.
Hmm, so that’s a real issue.
If the tablets dont have vibrators then it’s of no use at all
we are implementing this thing for a tablet based learning solution
which has games at the end of each chapter.
so so let me cross check, if the tablets we are pushing has vibrators or not.
I tried out your solution. I made fresh Vibrator.h and Vibrator.cpp files and removed ever pre-written code from them. And then added Vibrator.cpp to Android.mk
In the Vibrator.h itself, I am having following error at #endif which is the last line of your code of Vibrator.h
because of unmatched #endif. But I managed it by adding #ifndef VIBRATOR_H_ and#define VIBRATOR_H_ where #ifndef matches with previously unmatched #endif.
And the real error was in Vibrator.cpp
The positions/lines where error occurred in both Vibrate() and CancelVibrate():
1) JniMethodInfo t; Error:
Multiple markers at this line
- expected ‘;’ before ‘t’
- ‘JniMethodInfo’ was not declared in this scope
- suggested alternative:
2) if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, “vibrate”, “(I)V”)) Error:
Multiple markers at this line
- ‘JniHelper’ has not been declared
- ‘t’ was not declared in this scope
@code_game_chef: Very First thing , have you included jni & jnihelper properly as i have shown in my answer ?? & are these errors on android (eclipse) side ??
See , i have not received any this kind of error in my code … i have used it in cocos2d-x 3.2 on my mac 10.9.5 with latest Xcode 6 . with adt-bundle-mac-x86_64-20140702 SDK , with NDK_r9d . it jus working Fine .
if you can tell me more specific scenario then i might help you. but right now , i am not getting your issue.
Oh yes, in fact I have copy pasted your whole code. So, there isn’t any problem in inclusion.
In fact, I added the inclusion additionally to Vibrator.cpp as follows:
You told that I’ve not stated my details specifically. But I’ve already listed the detailed list of errors as in my last to last post… Also, I’ve quoted them along in this post.
I’ve also tried using:
Can you please help with this if I am not getting it from your way?
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "vibrate", "(I)V"))
What this CLASS_NAME is supposed to be?
First, I let it remain as CLASS_NAME
and then I changed it to Vibrator but nothing working…
But still the problem isn’t coming at CLASS_NAME but JniHelper even when I’ve included #include < jni.h> #include < android/log.h> #include “platform/android/jni/JniHelper.h”
explicitly in Vibrator.cpp even though the same is included through your code in Vibrator.h