MyGame is built with cocos2dx 2.2.6 and I’m having a process in java when calling C++ delegate using jni and trying to update label string it become a black rect even if I’m calling the delegate within android ui thread.
What I usually do to make it work is to make a CCCallFunc and then runAction
I did that however I’m getting error cannot resolve method runOnGLThread I see that it is declared under Cocos2dxHelperListener not Cocos2dxHelper so shall I implement this listener in my java code?
Thank you so much this work for me. You made my day
Cocos2dxActivity main = (Cocos2dxActivity) MyApplication.getCurrentAcivity();
main.runOnGLThread(new Runnable() {
@Override
public void run() {
// put your call to C++ here
}
});
I forgot to mention that I’m using cocos2dx 2.2.6. but current activity become null when app in background. so I will never getting my delegate called if the app in background. rather than I have to edit Cocos2dxHelper.java and add the needed method as
public static void runOnGLThread(final Runnable r) {
Cocos2dxHelper.sCocos2dxHelperListener.runOnGLThread(r);
}
@dimon4eg This Solve the problem when the app in foreground. But I still have the same issue if the delegate called when the app in background even if it is called from GLThread. Do you have any suggestion?
It is a download process and I’m updating progress and other buttons depending on the state. For the currentActivity it is not a problem. I found similar issue in cocos2dx v3. I will check if I could apply the changes to cocos2dx 2. Thanks for your time.
can you check is your app is background then mark some flag. After app goes to foreground check the flag and call that code.
Maybe this will fix your issue.