Try to avoid using the UI, because to adapt to IOS, ANDROID, WinPhone and other platforms => A new adaptation to a variety of platforms, reduce the difficulty of porting game engine Cocos2D-X
Cocos2D-X core is mainly written using C ++, peripheral code, such as OC, Android, C #
Github download Cocos2D-X
1. In the window operating system to build the development environment, the new version of the Cocos2D-X has no. bat file, you can
Http://download.csdn.net/detail/joejames/7331707download, configure cocos2dx of Visual studio to create the engineering plug-in
2. You can also refer to README. md in the directory to configure path, and then use scripts to create a project.
Some update packages of many games are mainly implemented using lua scripts, which is more convenient to replace and maintain.
AppDelegate. h and. cpp files: Project entry files, similar to the main function. IOS is the entry file of the program.
Bool AppDelegate: applicationDidFinishLaunching () will call this method after the program is started.
Void AppDelegate: applicationDidEnterBackground () the game will enter the background to call this method
Void AppDelegate: applicationWillEnterForeground () the game is about to enter the front-end. Call this method.
Generally, shared names in CC use the singleton mode, for example, the following director class.
// Initialize director
CCDirector * pDirector = CCDirector: shareddire ();
PDirector-> setOpenGLView (CCEGLView: Export dopenglview ());
// Turn on display FPS
PDirector-> setDisplayStats (true );
// Set FPS. the default value is 1.0/60 if you don't call this
PDirector-> setAnimationInterval (1.0/60 );
// Create a scene. it's an autorelease object
CCScene * pScene = HelloWorld: scene ();
// Run
PDirector-> runWithScene (pScene );
Return true;
Game elements: any elements that can be presented, such as scenes, layers, and genie
CCScene * scene = CCScene: create ();
HelloWorld * layer = HelloWorld: create ();
Scene-> addChild (layer );
AddChild method: place a game element in another game element. Only one game element is displayed when it is placed in other game elements that have already been presented.
When CCDirector runs scene, the layer on scene is displayed.
Virtual bool init (); Initialization Method:
// (1) initialize the parent class
If (! CCLayer: init ())
{
Return false;
}
// (2) create a menu and add it to the Layer
CCMenuItemImage * pCloseItem = CCMenuItemImage: create (
"CloseNormal.png ",
"CloseSelected.png ",
This,
Menu_selector (HelloWorld: menuCloseCallback ));
PCloseItem-> setPosition (ccp (CCDirector: shareddire()-> getWinSize (). width-20, 20 ));
CCMenu * pMenu = CCMenu: create (pCloseItem, NULL );
PMenu-> setPosition (CCPointZero );
This-> addChild (pMenu, 1 );
// (3) create a "Hello World" tag and add it to the Layer
CCLabelTTF * pLabel = CCLabelTTF: create ("Hello World", "Arial", 24 );
CCSize size = CCDirector: shareddire()-> getWinSize ();
PLabel-> setPosition (ccp (size. width/2, size. height-50 ));
This-> addChild (pLabel, 1 );
// (4) Create and add the wizard "“helloworld.png" to the Layer
CCSprite * pSprite = CCSprite: create ("HelloWorld.png ");
PSprite-> setPosition (ccp (size. width/2, size. height/2 ));
This-> addChild (pSprite, 0 );
BRet = true;