Cocos2d-x 3.8.1+cocos Studio 2.3.2 Insect capture in the control scene file in the skeletal animation

Source: Internet
Author: User
Tags addchild

cocos2d-x 3.8.1+cocos Studio 2.3.2 insect-catching control of skeletal animation in a scene file

Intro

This period of time has been trying to put in early versions of the Thumb solitaire game ( cocos2d-x 2.2.3+cocostudio 1.4.0.1 ) to the current relatively stable, tall environment-- cocos2d-x 3.8.1+cocos Studio 2.3.2 . The trip encountered a lot of trouble, time unconsciously like flowing water quietly passed away (this is I sometimes sour to think of "program ape" The main reason for the three words). Think twice, or try to record, one for their own memories may pass away, and secondly for some new partners to take a few pits and save a bit of time.

This article discusses how to control the code in the new version from the Cocos Studio The action of the skeletal animation added in the scene editor.

cpp-testsmisleading in the

learn from the web and some of the books you have on hand before you upgrade Cocos2d-x 3.x large changes in the version. So, it was very carefully decided to start by studying the most classic example engineering cpp-tests accompanying the new release . With a holistic approach, the original version of the code to start updating, there are some parts of the code, some of the studio Graphics Data section, of course, including the example game involved in the meter integration wall SDK related code updates and SHARESDK updates to the integration section.

Web search and Research sample project cpp-tests The results show that many of the official documents are obsolete. However, it is worth affirming that the engineering cpp-tests advocates to use the current latest cocos2d-x code manipulation in the early stages of almost all versions of Studio exported resource files, also including Flash animation files and Spine animation files, and so on.

Unfortunately, this is not indicated in the corresponding official information. Of course, there is no need to add such usage information too trivial in the sample project comments.

So, for the new version of enthusiasts like me, to use the latest technology provided by the main two ways: one is to view the official documents as fully as possible (but the latest version of the information about the poor), and then one is to read SDK source code.

The "misleading" shown in the title is partially reflected in the current latest cocos2d-x C + + Code Manipulation Studio the Export animation resource file aspect.

studio 2.3.2 ") The data file can only be Span style= "FONT-FAMILY:CALIBRI;" >.CSB file (scene file, layer file, node file, bone animation file, 3d .CSB

version ( 2.3.2 json file (if the selected language is Span style= "FONT-FAMILY:CALIBRI;" >javascript json file with early studio version exported exportjson file or json Span style= "font-family: ' The song Body '; > There are many inconsistencies in the file format.

Therefore, it should be clear that for the use of cocos2d-x 3.8.1 C + + of code manipulation Studio Version ( 2.3.2 The extension of the exported resource file should be . CSB file (binary file).

However, the engineering cpp-tests There is a large number of operations in the previous version of the scene file, GUI a large number of sample code for the layer file, skeleton animation file, and the official documents and these file comments are missing the necessary instructions, so it is easy to mislead beginners, and it wastes a lot of time to conduct feasibility coding test.

For the operation of skeletal animations in a new version of the environment I have not fully tested it, so only part of the test results are explained.

fromwww.cocoachina.comthe Revelation

in the above-mentioned website, the Cocos Skeleton animation function decryption ( http://www.cocoachina.com/cocos/20150907/13355.html in the article I capture the latest reference code as follows.

The CSB file exported by the Cocos Editor is first read through Csloader and the node returned by Csloader is converted to the skeletonnode* type skeletonnode* skeletonnode =  static_cast (Csloader::createnode ("DEMOPLAYER.CSB"));//After you get to the bone node, you can set the scale, position, and so on for the bone node skeletonnode- >setscale (0.2f); skeletonnode->setposition (150, 150);//Then add the Bone node to the parent node This->addchild (skeletonnode) ;//Next, read the CSB file exported by the Cocos Editor again by Csloader, creating a Actiontimeline object that stores all the animation of the bone node actiontimeline* action =  csloader::createtimeline ("DEMOPLAYER.CSB");//We set a tag value for the animation of the bone node so that the animation is easily removed from behind. It is recommended to use the enumeration form to define the tag value (for the convenience of writing 100 directly here) Action->settag, skeletonnode->runaction (action),//play the animation in the action (parameter 1: Animation name     Parameter 2: Loop play) Action->play ("Animation0",  false);//We can get this "block" by the name of a skin (image) above each bone node Skeleton const std::string weapbonename =  "Layer20";auto weaponhandebone =  Skeletonnode->getbonenode (weapbonename);//We can create a sprite and add it to the skin of the "block" bone that we just acquired auto weapskintoadd =  sprite::create ("Archerpeng/girl_arms.png"); weapsKintoadd->setname ("knife"); Weapskintoadd->setposition (VEC2 (135, 23)); Weapskintoadd->setscale ( 3.0f); weapskintoadd->setrotation (Weaponhandebone->addskin); (weapskintoadd, false);//load into the skin// The newly added skin is then displayed Weaponhandebone->displayskin (weapskintoadd, true);//can also be changed back to the original ("3" refers to the "3.png" The name of the original skin) Weaponhandebone->displayskin ("3",  true);
Node *node=csloader::createnode ("DEMOPLAYER.CSB");

is a 3.8.1 C + + Code Load Studio 2.3.2 Export the various . CSB a uniform way of binary resource files. However, according to my superficial analysis: more detailed data manipulation sample project is not provided at all.

The beginning of daylight

Here's a simple example I've created to illustrate how to C + + 3.8.1 operation in Code Studio 2.3.2 of the exported . CSB file.

first, take a look at my example project (I created a scene file MAINSCENE.CSD , which adds a skeleton animation file):

650) this.width=650; "title=" capture. JPG "alt=" wkiom1zj0vfd_nnmaaipvefmckm036.jpg "src=" http://s5.51cto.com/wyfs02/M01/76/17/wKiom1ZJ0vfD_ Nnmaaipvefmckm036.jpg "/>

skeletal animation files are DEMOPLAYER.CSD , as you will know at a glance.

650) this.width=650; "title=" capture. JPG "alt=" wkiom1zj0sicu-jtaans6uehgzs191.jpg "src=" http://s1.51cto.com/wyfs02/M00/76/17/ Wkiom1zj0sicu-jtaans6uehgzs191.jpg "/>

Next, the key positioning of the problem is: how to cocos2d-x 3.8.1 C + + code to manipulate the exported binary resources MAINSCENE.CSB , which in turn plays the skeletal animations and other finer-grained behavior controls for skeletal animation.

in the analysis of the above code hints and synthesis cpp-tests after the engineering code, I made the following bold attempt:

Node * RootNode = Csloader::createnode ("MAINSCENE.CSB");          node* child = Rootnode->getchildbyname ("Projectnode_1");         skeletonnode* arm = static_cast<skeletonnode*> (child);          AddChild (ARM);         actiontimeline* action = csloader::createtimeline ("MAINSCENE.CSB");         Arm->runaction (action); Action->gotoframeandplay (0);

Partial defects

in the cpp-tests often have the following code:

node* _rootnode = scenereader::getinstance ()->createnodewithscenefile ("Res/mainscene.json");

Coincidentally, there's an old version of my machine . Cocostudio 1.4.0.1 , the exported scene file is the JSON format. Experiments have shown that using cocos2d-x C + + 3.8.1 to manipulate scene files through the above code is very smooth. Of course, next, the code for the object in the corresponding further operation scenario is no problem, as is the case with the example project.

However, the simple source tracking found that Createnodewithscenefile files can also be used . CSB file as a parameter. Although there is no detailed study, the test proves that the following code is not feasible at all.

node* _rootnode = scenereader::getinstance ()->createnodewithscenefile ("RES/MAINSCENE.CSB"); node* child = _rootnode->getchildbyname ("Projectnode_1");

Similar to the above problem, there are still a lot of examples in the project, the students hope to be careful attention to the study.

Added

In the example file SceneEditorTest.cpp, there is a case where the. csb file is createnodewithscenefile loaded using the above method. For example, the following function is shown:

650) this.width=650; "title=" capture. JPG "src=" http://s1.51cto.com/wyfs02/M01/76/16/wKioL1ZJ4TOBKaTlAAH9rxeeokw291.jpg "alt=" Wkiol1zj4tobkatlaah9rxeeokw291.jpg "/>

Note that the Loadfilechangehelper code for the related helper function is as follows:

void Sceneeditortestbase::loadfilechangehelper (std::string& filepathname) {Std::string::size_type n = Filepathname.find_last_of ("."); if (n = = Std::string::npos) return; Filepathname = Filepathname.substr (0,n); if (_iscsbload) Filepathname.append (". CSB"); Else Filepathname.append (". JSON");}

And the above example, which is part of cpp-tests, is successfully debugged on my machine. In other words, createnodewithscenefile can indeed load the. csb file, but it is not a. csb file that Cocos Studio 2.3.2 exports. According to my estimate, the. csb file should be exported from an earlier version of studio.

What do you think? Feel a bit of trouble. different. csb files can actually be loaded through createnodewithscenefile, and some can't! Unfortunately, the official did not give a clear explanation!!!

Small Summary

dare not say some more, because I arrive at this conclusion only to stay in one-sided. However, there is some basic certainty: The examples provided in the current cpp-tests for early STUDIO Resource operations are very rich, but in contrast, for the latest version of the STUDIO Binary exported . CSB An in- depth sample of the file provides a very poor example. Therefore, in this case, in order to use the latest version of Studio and the corresponding version of the Cocos2d-x 3.x version, the further study of the SDK The source code is required, but it also combines the best possible new examples on the web (especially from cocoachina.com network resources).

This article is from the "Green Peak" blog, please make sure to keep this source http://zhuxianzhong.blog.51cto.com/157061/1713250

Cocos2d-x 3.8.1+cocos Studio 2.3.2 Insect capture in the control scene file in the skeletal animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.