Cocos2d_x_01 _ environment construction and cocos2d_x_01 Environment Construction
Finally:
Mac installation Cocos2d-x-3.3:
Reference:
Online API list:
The Cocos2d-x-3.3 version from configuration installation to project creation is a command line
- Official website to download the latest version of Cocos2d-x-3.3, size of about 280 M
-
- Decompress the package and go to terminal.
Switch directory
To the decompressed directory, and then execute./setup.py
, Press enter, as shown in.
-
- There will be several inquiries during this period, whether to set the android SDK path,
- If you have not installed the Android development environment, you can directly
Enter
Skip, not set at the moment
- (You can configure it in the following files in the future:/etc/profile)
123 |
->Please enter the path of NDK_ROOT (or press Enter to skip): ->Please enter the path of ANDROID_SDK_ROOT (or press Enter to skip): ->Please enter the path of ANT_ROOT (or press Enter to skip):
|
As prompted, hit the command:
source /Users/history/.bash_profile
Then
Enter
In this way, even if it is set.
1 |
Please execute command: "source /Users/history/.bash_profile" to make added system variables take effect
|
123456 |
Running command: new> Copy template into /Users/beyond/Desktop/project/cocos2d_x> Copying cocos2d-x files...> Rename project name from 'HelloCpp' to 'cocos2d_x'> Replace the project name from 'HelloCpp' to 'cocos2d_x'> Replace the project package name from 'org.cocos2dx.hellocpp' to 'com.beyond'
|
Open the automatically created ProjectYou can select a desktop application, directly use command + R, and compile and run the application.
After waiting for n minutes, I finally ran out ~
Add the following: Enter the terminal for the configuration of the NDK directory and enter the command: sudo nano/etc/profile to open the file for configuring environment variables.
Add the NDK_ROOT, ANT, and SDK directories based on the actual situation. The example is as follows:
The following is an analysis of the HelloWorld program:
Main. m entry
Application proxy AppDelegate. h
# Ifndef _ APP_DELEGATE_H _ # define _ APP_DELEGATE_H _ # include "cocos2d. h "/** @ method Description: The cocos2d Application. the reason for implement as private inheritance is to hide some interface call by Director. * ///: private indicates the inherited class, which is changed to private class AppDelegate: private cocos2d: Application {public: // null parameter constructor AppDelegate (); // destructor virtual ~ AppDelegate (); virtual void initGLContextAttrs ();/** @ method Description: Implement Director and Scene init code here. @ return: true: initialization successful, application running @ return: false initialization failed, application terminated */virtual bool applicationDidFinishLaunching ();/*** @ method description: after the application enters the background, it calls @ parameter: the pointer of the application */virtual void applicationDidEnterBackground ();/** @ method Description: the application will call @ parameter when it enters the foreground: the pointer of the application */virtual void applicationWillEnterForeground () ;}; # endif/_ APP_DELEGATE_H _
Application proxy AppDelegate. cpp
# Include "AppDelegate. h" # include "HelloWorldScene. h" USING_NS_CC; AppDelegate: AppDelegate () {} AppDelegate ::~ AppDelegate () {}// if you need a different context, you only need to modify the value of glContextAttrs. // it will takes effect on all platformsvoid AppDelegate: initGLContextAttrs () {// sets the OpenGL context attribute. The directory can have only six attributes. // red, green, blue, alpha, depth, stencel GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; GLView: setGLContextAttrs (glContextAttrs);} bool AppDelegate: applicationDidFinishLaunching () {// instantiate the director class director auto director = Dir Ector: getInstance (); auto glview = director-> getOpenGLView (); // if glview is empty, create an if (! Glview) {glview = GLViewImpl: create ("My Game"); director-> setOpenGLView (glview);} // display frame rate FPS director-> setDisplayStats (true ); // sets the FPS. the default value is 1/60 seconds director-> setAnimationInterval (1.0/60); // create a scenario to automatically release it's an autorelease object auto scene = HelloWorld: createScene (); // director running scenario director-> runWithScene (scene); return true;} // This function will be called when the app is inactive. when comes a phone call, it's be invoked toovoid AppDelegate: applicationDidEnterBackground () {Director: getInstance ()-> stopAnimation (); // if you use SimpleAudioEngine, it must be pause // SimpleAudioEngine: getInstance ()-> pauseBackgroundMusic ();} // this function will be called when the app is active againvoid AppDelegate: applicationWillEnterForeground () {ctor: getInstance ()-> startAnimation (); // if you use SimpleAudioEngine, it must resume here // SimpleAudioEngine: getInstance ()-> resumeBackgroundMusic ();}
Layer HelloWorldScene. h
# Ifndef _ HELLOWORLD_SCENE_H __# define _ HELLOWORLD_SCENE_H __# include "cocos2d. h "// actually inherited from Layerclass HelloWorld: public cocos2d: Layer {public: // There is no id type in cpp, so we recommend returning the class instance pointer static cocos2d :: scene * createScene (); // Here's a difference. method 'init 'in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone virtual bool init (); // The callback Method void menuCloseCallback (cocos2d :: ref * pSender); // implement the "static create ()" method manually CREATE_FUNC (HelloWorld );}; # endif/_ HELLOWORLD_SCENE_H __< span style = "font-family: Courier New; color: #393939;"> <span style = "font-size: 24px; line-height: 32px; background-color: rgb (245,245,245); "> <strong> </span>
Layer
HelloWorldScene. cpp
# Include "HelloWorldScene. h "USING_NS_CC; Scene * HelloWorld: createScene () {// 'Scene 'Automatically releases auto scene = scene: create (); // 'player' Automatically releases auto layer = HelloWorld: create (); // adds the layer to the scene-> addChild (layer ); // return the scenario of filling the layer: return scene;} // on "init" you need to initialize your instancebool HelloWorld: init () {// 1. call the init of the parent class. if (! Layer: init () {return false;} // screen Size visibleSize = Director: getInstance ()-> getVisibleSize (); // 2D coordinate Vec2 origin = Director: getInstance ()-> getVisibleOrigin (); /// // 2. add a menu item with "X" image, which is clicked to quit the program // add a "close" icon to exit the progress. it's an autoreltailobject auto closeItem = MenuItemImage: create ("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1 (HelloWorld: menuCloseCallback, this )); closeItem-> setPosition (Vec2 (origin. x + visibleSize. width-closeItem-> getContentSize (). width/2, origin. y + closeItem-> getContentSize (). height/2); // create menu, it's an autorelease object auto menu = Menu: create (closeItem, NULL); menu-> setPosition (Vec2 :: ZERO); this-> addChild (menu, 1 ); /// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = LabelTTF: create ("Hello Beyond", "Marker Felt", 50 ); // position the label on the center of the screen label-> setPosition (Vec2 (origin. x + visibleSize. width/2, origin. y + visibleSize. height-label-> getContentSize (). height); // add the label as a child to this layer this-> addChild (label, 1); // add "HelloWorld" splash screen "auto sprite = Sprite :: create ("HelloWorld.png"); // position the sprite on the center of the screen sprite-> setPosition (Vec2 (visibleSize. width/2 + origin. x, visibleSize. height/2 + origin. y); // add the sprite as a child to this layer this-> addChild (sprite, 0); return true;} void HelloWorld: menuCloseCallback (Ref * pSender) {# if (CC_TARGET_PLATFORM = CC_PLATFORM_WP8) | (CC_TARGET_PLATFORM = CC_PLATFORM_WINRT) MessageBox ("You pressed the close button. windows Store Apps do not implement a close button. "," Alert "); return; # endif Director: getInstance ()-> end (); # if (CC_TARGET_PLATFORM = CC_PLATFORM_IOS) exit (0); # endif}
Vs2010 build cocos2d-x Development Environment
Hi, I used VS2012 + cocos2d-x and didn't hit you.
Installing cocos2d-x on xcode doesn't matter to you either.
Let me give you a reference.
V.youku.com/v_show/id_xndy4ndcyotq1_html
This brainless cocos2d tutorial is still good. I just read it.
Hope to help you!
Cocos2d-x + eclipse development environment, can be detailed
Follow this article.
Www.cnblogs.com/..0.html