COCOS2DX no nonsense introduced, very fire game engine, the key is it open source, can be free to download, study, development, do not engage so many active things. The following is an example of COCOS2DX 2.x to illustrate some basic things about this platform. Although now COCOS2DX already go to the stable version of 3.x, but the reason to choose COCOS2DX 2.x version, mainly this aspect of the information is more, originally engaged in cocos2dx people are not much, engaged in a few people write programming records, No data, just a bunch of hard-to-read official documents, COCOS2DX 3.x, basically equals blindness.
First of all, since the main platform of this engine in Windows is written by familiar C + +, so COCOS2DX 2.x development, you first have to prepare visual Studio 2010 and above version. If you choose Cocos2dx 3.x, you also need to support the preparation of visual Studio 2012 or more versions. Visual Studio 2008 is not supported anymore, that's all. Download a full installation. On the Internet a search a bunch, do not say.
After that, since COCOS2DX 2.x is no longer available in the final version of today's website 2.2.6 installwizardforvs2010.js This ghost, you need to create a new project in the Python language, so you can see my previous "Python" The configuration of the Windows version of the Python development environment, Helloworld,python Chinese issues, input and output, conditions, loops, arrays, classes (click to open the link) first with a good python2.x environment.
Then, you are in COCOS2DX's Chinese official website (click Open link), such as, pull to the bottom, download COCOS2DX 2.x version.
Specifically: http://54.192.159.100/cocos2d-x-2.2.6.zip?fid=d2qko-*f7vaabuj7fijgqlgs5hzdkv4yaaaaaoeox4e0-gk5frkd* Y-bb8j7lcvn&mid=666&threshold=150&tid=5d3fd9855047216e67d27c85e859fc2d&srcid=119&verno=1
After downloading, get a cocos2d-x-2.2.6.zip, decompression, this decompression location is your future COCOS2DX development environment, project directory, and PHP is the same, bad migration, please choose carefully.
In your cocos2dx extract directory find Build-win32.bat This thing, double-click Run.
Experience a lengthy compilation process like this:
After doing well, the following interface will appear, cocos2dx a large set of examples of official offers, interested to see after, can be directly closed.
At this point, the configuration of the COCOS2DX is complete.
Below create a helloworld of our own, do not use the official example, there is no clue.
Use the command line to enter the. \cocos2d-x-2.2.6\tools\project-creator folder, using Python commands, such as creating a project.
Create_project.py-project your project folder name-package package name-language Development language (basically CPP, does not rule out that the great God is proficient in the hog stream of Lua, nor is it recommended to use JavaScript development!) )
In the process of creation, may be like the error, no tube, because you created the Mydemo project has successfully appeared in the. \cocos2d-x-2.2.6\projects folder, enter. \cocos2d-x-2.2.6\projects\mydemo\ Proj.win32 opens HelloCpp.sln and starts to develop the game on Windows with the COCOS2DX Engine (framework).
You can observe that in. \cocos2d-x-2.2.6\projects\mydemo, where the proj.android, Proj.ios, and other platforms are present, it means that you can also use the COCOS2DX Engine (framework) for development on these platforms. Not to say a platform development, multi-platform co-compilation ...
After you open HelloCpp.sln and wait for visual Studio 2010 to load a whole bunch of external libraries, you can see the following file structure:
First of all, you have to understand the concept that the simplest HelloWorld in COCOS2DX is made up of a scene called HelloWorld, and then put a HelloWorld string on this HelloWorld scene,
The official initial HelloWorld also helloworld the scene with a background image, a close button, and so on assorted, making the HelloWorld file look more complicated.
We start with the main.cpp and AppDelegate.cpp, first set up a good program of some basic things.
The first is main.cpp, the main function of this thing is 5 lines of code, the Program title and window size of 18, 19 lines to modify, as follows:
#include "main.h" #include "AppDelegate.h" #include "CCEGLView.h" Using_ns_cc;int apientry _tWinMain (hinstance HINSTANCE, hinstance hprevinstance, LPTSTR lpcmdline, int ncmdshow) { unreferenced_ PARAMETER (hprevinstance); Unreferenced_parameter (lpcmdline); Create the application instance appdelegate app; cceglview* Eglview = Cceglview::sharedopenglview (); Eglview->setviewname ("HelloWorld");//Modify the program to run with the title HelloWorld eglview->setframesize (1024, 768);// The program runs in the size of 1024x768 return ccapplication::sharedapplication ()->run ();}
The rest of the code can not understand the temporary first, just like you learned C language, do not care about #include<stdio.h> and void Main () {} is what ghost, you first will change the contents of printf (). About introduction, function of these things, come back to learn.
After, has not changed, the AppDelegate.cpp to modify, the 22nd line of the frame number of debugging information off, the number of frames in the 25th line of interest can be changed, but changed also see no effect, modified as follows:
#include "AppDelegate.h" #include "HelloWorldScene.h" USING_NS_CC; Appdelegate::appdelegate () {}appdelegate::~appdelegate () {}bool appdelegate::applicationdidfinishlaunching () {// Initialize director ccdirector* Pdirector = Ccdirector::shareddirector (); cceglview* Peglview = Cceglview::sharedopenglview (); Pdirector->setopenglview (Peglview); Turn on display fps pdirector->setdisplaystats (false);//Turn off Debug Info//Set FPS. The default value is 1.0/60 if you do not call this pdirector->setanimationinterval (1.0/60);//Here is the set game run frame number locked to 60, general bull b Machine, cow B game are lock this frame number, 30 frames is low//create a scene. It ' s an Autorelease object ccscene *pscene = Helloworld::scene (); Run Pdirector->runwithscene (pscene); return true;} This function was called when the app was inactive. When comes a phone Call,it's be invoked toovoid Appdelegate::applicationdidenterbackground () {Ccdirector::shareddirect or ()->stopanimation (); If you use Simpleaudioengine, it must is Pause//Simpleaudioengine::sharedengine ()->pausebackgroundmusic ();} This function would be called when the app is active againvoid Appdelegate::applicationwillenterforeground () {Ccdire Ctor::shareddirector ()->startanimation (); If you use the Simpleaudioengine, it must resume here//Simpleaudioengine::sharedengine ()->resumebackgroundmusic ();}
The rest of what initialization code and so on, do not understand, do not control, do not change.
Then, to the core of the entire program, management HelloWorld This scene of the HelloWorldScene.cpp to modify, put on our own things, remove the official things. The main HelloWorldScene.cpp in the initialization parameter bool Helloworld::init () {} modified, the rest do not move, the entire HelloWorldScene.cpp modified as follows:
#include "HelloWorldScene.h" USING_NS_CC; ccscene* Helloworld::scene () {//' scene ' is an Autorelease object ccscene *scene = Ccscene::create (); ' Layer ' is an Autorelease object HelloWorld *layer = Helloworld::create (); Add layer as a child to scene scene->addchild (layer); Return the scene return scene;} On the "Init" need to initialize your Instancebool helloworld::init () {//Keep the initialization part already in place, do not modify, start if (! Cclayer::init ()) {return false; } ccsize visiblesize = Ccdirector::shareddirector ()->getvisiblesize (); Ccpoint origin = Ccdirector::shareddirector ()->getvisibleorigin (); Keep the initialization part that already exists, do not modify, end cclabelttf* Plabel = Cclabelttf::create ("Hello World", "Arial", 96);//Declare a label text HelloWorld, Its font is Arial, the font size is Plabel->setposition (CCP (origin.x + visiblesize.width/2,//setting label text position CCP is required, visiblesize.width/ 2 for the center of the screen, the front origin.x is to be added, used for multi-platform fixed position ORIGIN.Y + VISIBLESIZE.HEIGHT/2);//y part of the same this-> AddChild (Plabel, 1);//put this label text HelloWorld into the scene, the cascade relationship is 1, equivalent to the Z-index in the CSS, the larger the number, the more it return true;} void Helloworld::menuclosecallback (ccobject* psender) {#if (Cc_target_platform = = CC_PLATFORM_WINRT) | | (Cc_target_platform = = CC_PLATFORM_WP8) Ccmessagebox ("You pressed the Close button. Windows Store Apps do not implement a close button. "," "Alert"); #else ccdirector::shareddirector ()->end (); #if (Cc_targ Et_platform = = Cc_platform_ios) exit (0); #endif #endif}
Use Ctrl+f5 to run, or click the Run button above to see the following effect:
If you encounter "Link:fatal error LNK1123: Failed during conversion to COFF during compile time: invalid or corrupt file" error:
The problem with COCOS2DX is that there are multiple Visual Studio conflicts in the computer, or that previous versions of Visual Studio were not uninstalled cleanly. There are two cvtres.exe files in the current system and there will be a problem with different versions. We let VS2010 directly use the system's Cvtres.exe program. Rename or delete: (the location of the VS2010 installation). \vc\bin\cvtres.exe
, I'll get Cvtres.exe into _cvtres.exe.
In conclusion, COCOS2DX's HelloWorld is much simpler than SSH, and the code is clear. The key is to pay attention to the good version, just as php5.5 does not support windows2003, you have to figure out that visual Studio 2010 can only support COCOS2DX 2.x and so on. Is the installation may be a bit cumbersome, after all, the installation of the Python environment for many people is unfamiliar, Visual Studio 2010 installation time is not able to spit slot, plus COCOS2DX 2.x compilation process, is relatively long. The main online many of the information on the pain of the egg will not say ...
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Download, install, and configure COCOS2DX 2.x under the "COCOS2DX" Windows platform to create your own HelloWorld