Quick cocos2d x Phone (Android) startup process Learning

Source: Internet
Author: User

Briefly learn the process of starting the Quick cocos2d x in Android.
The first thing to know: Quick cocos2d x is a game interface that relies on Android activity and Glsurfaceview (inherited from Surfaceview) to display the quick layer.

(1) First the Quick class Android game starts with the activity (assuming AC) specified from the Androidmanifest.xml file.

(2) AC inherits the cocos2dxactivity of the parent class.

(3) Call static initialization block, load COCOS2DX's dynamic library, that is, some C + + methods. Because you will call native's C + + method in Java later, run COCOS2DX.

(4) Start the program, execute the AC onCreate () function, call the Super.oncreate () function (that is, Cocos2dxactivity's onCreate () function)

(5) After entering the OnCreate function of the parent class, an important component is initialized. That's mglsurfaceview. Note the declaration period function interface of the parent class.

Such as:

The Onresume () and OnPause () interfaces of the activity are mainly for Mglsurfaceview drawing control.

This way, when the game enters the background, call the activity life cycle function, pause the game drawing and so on related processing.

(6) Mglsurfaceview set render rendering.

Execute This.mGLSurfaceView.setCocos2dxRenderer (new Cocos2dxrenderer ()) to set rendering render.

Inside the Cocos2dxrenderer, call the following code:

@Override
public void onsurfacecreated (final GL10 pGL10, final EGLConfig peglconfig) {
  Cocos2dxrenderer.nativeinit (This.mscreenwidth, this.mscreenheight);
This.mlasttickinnanoseconds = System.nanotime ();
IsReady = true;
}

The red code above will be the C + + method, into the COCOS2DX entrance, the game is about to start.

Take a look at the following Nativeinit method to do something:

Notice the Appdelegate class above, where Appdelegate is initialized.
Appdelegate code is mainly set the script engine, the director Ccdirector parameter settings, the game before and after the switch processing.
With the scripting engine Setup, you can execute LUA scripts in the game. Run the game through LUA scripts.
With tolua++, Lua can invoke C + + code, which is COCOS2DX code, using the game engine cocos2dx.
Run this game!
As for Appdelegate, a separate blog is required.

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.