This article: cocos2dx+vs2013 environment to create projects, some code analysis. Friends of the meeting can skip.
In front of the simple installation of a few environments, the program can run smoothly (other cocos-stadio these need to be re-installed)
1. Create a custom project in the command line form
Open the cocos2d root directory, run the download-deps.py and setup.py once (you can start a new project directly if you have previously run)
Version 3.2 seems to be back in the form of commands, and it is not troublesome, so I have not found another way to create the project.
Here is a look at the two commands, enter each to see what parameters they have
Cocos and Cocos New
Cocos New project name –P package name –l cpp–d path
Official start: In the Cocos root directory shift opens the command window:
Cocos New Firstdemo-p com.huoit.firstdemo-l cpp-d F:\CocosDemo Enter
Some friends may think of the new project with batch processing, not complicated, direct reference to the user wrote, Save As. bat file next time directly run can
@echo off =============cocos2d-x New Project ============== set /P name= Enter the name of the project:%name% Echo Creating new Project ... set pack=new %name%-P%pack%%name%-L CPP- D F:\Cocos2dDemo echo Creation is complete. pause
Here I build project Firstdemo
2. Project Catalogue
After the creation is complete, open the solution Firstdemo\proj.win32\firstdemo.sln under the corresponding project directory. The following file structure
Open Win32 See Main.cpp\main.h Program entrance, classes folder defined Appdelegate and Helloworldscene
3, HelloWorld
Before you go on, learn the concepts of directors, scenes, layers, and sprites.
The director is a game flow controller, the next game can be divided into different scenes, a scene can be divided into different layers, a layer can also have any visible game nodes (that is, the game is basically all the classes are sent to node class nodes). You can perform an action to modify the properties of a game node so that it moves, rotates, zooms in, shrinks, and so on.
①:main.cpp Entrance, program walk
appdelegate app; //Inherit from application return Application::getinstance ()->run (); //Run
②:appdelegate.h See the introduction of namespaces and macros, constructor destructor, here the main look at three functions represent the life cycle of the program, the first is the loading time to initialize the director scene these, the next two is the program background and backstage back to the foreground function (below), the source code in the comments are actually clear, you can view their own
/* * Load Initialization * /virtualbool applicationdidfinishlaunching (); /* * foreground to Background run */ virtualvoid Applicationdidenterbackground (); /* * Background to the foreground run */ virtualvoid Applicationwillenterforeground ();
corresponding to the implementation of the CPP, mainly to do the few things
Load: Initialize Director,glview, set fps. Initialize the scene, run;
Backstage: Director calls StopAnimation
Front Desk: Director calls Startanimation
③:helloworld, see it inherit layer
classHelloWorld: Publiccocos2d::layer{ Public: //there ' s no ' id ' in CPP, so we recommend returning the class instance pointer Staticcocos2d::scene*Createscene (); //Here ' s a difference. Method ' init ' in cocos2d-x returns BOOL, instead of returning ' ID ' in Cocos2d-iphone Virtual BOOLinit (); //a selector callback voidMenuclosecallback (cocos2d::ref*Psender); //implement the "Static Create ()" Method manuallyCreate_func (HelloWorld);};
HelloWorldScene.h
Before declaring a scene, initialize Init (), and a scheduling method. The main point here is a create_func (HelloWorld);
How to understand that, the definition of this macro is somewhat similar to the generic in C #, create () An instance of the corresponding type.
Cpp:
The Auto keyword is a bit like the C # var, but it should also be the right object type to be explicitly equal to
Director::getinstance ()->getvisiblesize (); Get the visible size
Director::getinstance ()->getvisibleorigin (); Get coordinates starting point
SetPosition Setting Location
AddChild (object, z-axis position): Recall the above tree structure, that is, the lower-level objects into the parent object container (Sprite join Layer,layer join scene)
Implementation notes in CPP very detailed, no more nonsense, here is just a summary of notes, and more look at the official documents and code
Also to say is from the simple HelloWorld see 3.2 inside of small changes, that is, the class cocos2d under the namespace is again encapsulated, see the previous version of the cc_break_if these are not seen, only from the writing concise a little
COCOS2DX Development (4)--windows environment create COCOD2DX 3.2 first project HelloWorld