Beginner, various problems, different versions found
From: http://xiaominghimi.blog.51cto.com/2614927/969984
Cocos2dx V2.0 version released for a while, now the latest version is cocos2d-2.0-rc2-x-2.0.1; this time himi on 2. the new version of X has also been noticed and used. It has been found that many changes have been made. The latest himi project is coming to an end, so the engine has not been updated to the latest version. Starting today, himi will gradually use some of the latest v2.x versions, synchronously update some frequently-used changes, and publish blog posts worth noting to share with you;
Previously we used cocos2dx 1. in Version X, we all know that creating a ccobject class is the class name and then: the class name removes the CC rule to create and initialize, but this one is in cocos2dx 2. the X version will not work, in cocos2dx 2. in Version X, the initialization and creation classes are basically created at the beginning of the create keyword.
First, let's take a look at the first change: cclayer Initialization
Custom layer, Class Name: World
In. h: layer function layer_node_func (World) in 1.x; layer function layer_create_func (World) in 2.x );
. CPP: 1. rewrite function of Version X: ccscene * World: Scene () {ccscene * scene = ccscene: node (); World * layer = World: node (); scene-> addchild (layer); Return scene;} 2. rewrite function of Version X: ccscene * World: Scene () {ccscene * scene = ccscene: Create (); World * layer = World: Create (); scene-> addchild (layer); Return scene ;}
Then let's look at the initialization of the second common ccarray:
1. X version of ccarray creation: ccarray * array = ccarray: array (); 2. x version of ccarray creation: ccarray * array = ccarray: Create ();
Third, let's look at the usage of the ccfileutils function related to the file path:
1. use of Version X: const char * fullpath = cocos2d: ccfileutils: fullpathfromrelativepath (patha. c_str (); 2. use of Version X: const char * fullpath = cocos2d: ccfileutils: sharedfileutils ()-> fullpathfromrelativepath (patha. c_str ());
Create the fourth genie:
1. X creation: ccsprite * sp = ccsprite: spritewithfile ("himi.png"); 2. x: ccsprite * sp = ccsprite: Create ("himi.png ");
Fifth register touch screen event listening:
1. register in X: cctouchdispatcher: shareddispatcher ()-> addtargeteddelegate (this, 0, false); 2. register in X: ccdirector: shareddirector ()-> gettouchdispatcher ()-> addtargeteddelegate (this, 0, false );
Sixth particle correlation
1. X particle creation and setting automatic release setting ccparticlesystem * tempsystem = ccparticlesystem: FIG ("himi. plist "); tempsystem-> setisautoremoveonfinish (true); 2. X particle creation and setting automatic release settings ccparticlesystem * tempsystem = ccparticlesystemquad: Create ("himi. plist "); tempsystem-> setautoremoveonfinish (true );
Seventh: remove the ccfiledata class:
1. use of ccfiledata of X: cocos2d: ccfiledata filedataclip (const char * pszfilename, const char * pszmode); 2. the ccfiledata in X is deleted and can be replaced by the following function: ccfileutils: sharedfileutils ()-> getfiledata (const char * pszfilename, const char * pszmode, unsigned long * psize)
Eighth action use and creation:
1. create and use X actions: This-> runaction (ccsequence: Actions (ccmoveto: actionwithduration (ccpdistance (this-> getposition (), target)/velocity, target ), cccallfunc: actionwithtarget (this, callfunc_selector (Player: removetarget), null); 2. create and use the action of X: This-> runaction (ccsequence: Create (ccmoveto: Create (ccpdistance (this-> getposition (), target)/velocity, target ), cccallfunc: Create (this, callfunc_selector (Player: removetarget), null ));
In fact, the above examples are representative. I think we can find some different rules. The differences in cocos2dx V2.0 are described in this article. In the future, if himi finds that there are more important differences, it will be shared in the blog.