Cocos2DX C ++ adjusts Java non-static functions.

Calling java non-static functions in Cocos2dx C++.

Calling the non-static method in JAVA in CPP requires obtaining the object of Activity first. This is the difference.

Declare a static variable in AppActivity
public span> static AppActivity con;
to this variable in the create of AppActivity Assignment
@Override public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); con = this; }
Add a method to obtain the object in AppActivity
public static Object returnActivity() {return con; }
Add method in cpp
void HelloWorld::onClickLogin(){#if(CC_TARGET_PLATFORM < span class="hljs-subst">== CC_PLATFORM_ANDROID) {JniMethodInfo info; jobject activityObj; bool isHaveObj = JniHelper::getStaticMethodInfo(info, "org/cocos2dx/cpp/AppActivity", "returnActivity"< /span>, "()Ljava/lang/Object;"); if (isHaveObj) {activityObj = info.env->CallStaticObjectMethod( info.classID, info.methodID); log span>("jni:obj has find.");} else {log("jni:obj is null");} JniMethodInfo methodInfo; bool isHaveMethod = JniHelper::getMethodInfo(methodInfo, "org/cocos2dx/cpp/AppActivity", "onClickLogin", "() V"); if (isHaveMethod) {methodInfo.env->CallVoidMethod(activityObj, methodInfo.methodID);} }#endif}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3674 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.