Cocos2d-x simple recording of the mating on Android

Source: Internet
Author: User

General Android Project entry:

Src/org/cocos2dx/cpp_empty_test_diff/mainactivity.java

Cocos2d-x entrance slightly different

Src/org/cocos2dx/lib/cocos2dxactivity.java

See Onloadnativelibraries loading NDK compilation generated by. So

The application is now started.

Then use JNI to invoke C + + content and launch the game engine.

The specific is:

Cocos2dxactivity.java Init, Oncreateview

New Cocos2dxglsurfaceview(This)

Cocos2dxglsurfaceview extends Glsurfaceview event callback function similar to Win32, involving keyboard and touch, etc.

Cocos2dxactivity.java Init in This.mGLSurfaceView.setCocos2dxRenderer (new cocos2dxrenderer());

Cocos2dxrenderer Implements Glsurfaceview.renderer

See the public void Ondrawframe(final GL10 GL) function, which is the starting point of the engine's cycle

Does not care about frame rate processing, the function is simply called the Cocos2dxrenderer.nativerender();

Back to Cocos2dxactivity.java

private static native void Nativerender ();

private static native void Nativeinit (final int pWidth, final int pheight);

These functions are the knowledge of JNI and the implementation of the method in. So

respectively:

void Jnicall Java_org_cocos2dx_lib_cocos2dxrenderer_nativerender in java_org_cocos2dx_lib_cocos2dxrenderer.cpp

The java_org_cocos2dx_lib_cocos2dxrenderer_nativeinit in Javaactivity-android.cpp

    void Jnicall Java_org_cocos2dx_lib_cocos2dxrenderer_nativerender (jnienv* env) {        cocos2d::D irector::getinstance ()mainloop ();    }

Can see the call of Mainloop;

void Java_org_cocos2dx_lib_cocos2dxrenderer_nativeinit (jnienv*  env, Jobject thiz, Jint W, Jint h) {        = Director->Getopenglview ();         = Cocos2d::glviewimpl::create ("Android app");        Glview//  frame Size first-hand information        director->setopenglview (glview);        Cocos2d::application::getinstance ()//  The run here is empty    }

The rest of the process is basically the same as the iOS process, see "cocos2d-x Simple recording on iOS";

Not familiar with Android, just log on to this

Cocos2d-x simple recording of the mating on Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.