Cocos2d-x 3.8.1 The Skeletal animation loading method Addarmaturefileinfo still has problems

Source: Internet
Author: User
Tags addchild

It is very awkward to put forward the problems shown in title, but it is true. As a result, Cocos Studio (which I am currently using 2.3.2) has improved in many ways, including the Code manipulation section in the corresponding cocos2d-x.

Problem

At present, my test results show that using Cocos2d-x 3.8.1, the following methods are available:

Armaturedatamanager::getinstance ()->addarmaturefileinfo (filename);

The Skeleton animation resource file exported by Cocos Studio 2.3.2 cannot be loaded properly. For example, the following code does not build properly through the project :

Armaturedatamanager::getinstance ()->addarmaturefileinfo ("DEMOPLAYER.CSB");

A regrettable example

Nonetheless, the cpp-tests instance of Cocos2d-x 3.8.1 does provide an example of using the Addarmaturefileinfo method to load. CSB skeletal animation files!!

Yes, because the. csb file is in binary format and is not currently found in its anti-compilation tool, however, the example provided in the Cpp-tests instance is parsed from the use of simple tools. CSB Skeleton animation files version with Cocos Studio 2.3.2 Exported Skeleton animation resource file. The CSB is inconsistent.

The following is a comparison of the result graphs observed by notepad++ (the 1th one is Cocos Studio 2.3.2 Export Skeleton Animation file DEMOPLAYER.CSB View the results, obviously the version number is 2.1.0.0, and the 2nd is the example COWBOY.CSB skeleton animation file provided in the Cpp-tests instance to see the results, obviously the version number is 1.0.1):

650) this.width=650; "title=" capture. JPG "src=" http://s2.51cto.com/wyfs02/M02/76/21/wKioL1ZLIqGBpW75AALR_GQJDyo639.jpg "alt=" wkiol1zliqgbpw75aalr_ Gqjdyo639.jpg "/>

650) this.width=650; "title=" capture. JPG "src=" http://s4.51cto.com/wyfs02/M02/76/24/wKiom1ZLIxmC3MHpAAQDiObULoI450.jpg "alt=" Wkiom1zlixmc3mhpaaqdiobuloi450.jpg "/>

In order to further analyze the above problems, I also specifically put cocos2d-x 3.8.1 is provided in the Cpp-tests instance by using the Addarmaturefileinfo method to load the corresponding. CSB Skeleton animation file code copied to a simple sample project for testing, indeed OK. The relevant code looks like this:

const  char* helloworld::m_binaryfilesnames[4] =  {  "BEAR.CSB",  "HORSE.CSB", "COWBOY.CSB", "CCC.CSB"};const  char* helloworld::m_ armaturenames[4] = {  "Bear",  "horse", "Cowboy", "Skeleton1"};//...... // load  from binary armaturedatamanager::getinstance ()->addarmaturefileinfo (m_binaryFilesNames[3]);  armature *m_armature = armature::create (m_armaturenames[3]); m_armature-> Getanimation ()->playwithindex (0);  m_armature->setscale (1.0f); size size =  Director::getinstance ()->getwinsize ();  m_armature->setposition (SIZE.WIDTH/2, SIZE.HEIGHT/2);  addchild (m_armature); 

For the corresponding first three. csb files in the array (which should be the old version of studio exported skeleton Animation CSB file), running the above code is very smooth (of course, the above Addarmaturefileinfo method calls the earlier Exportjson skeleton animation file is also able to run smoothly). In fact, cpp-tests nature has also been debugged on my machine sequentially through (my environment is Windows 7 64bits Visual Studio 2013). However, for the last CSB file (the Skeleton animation file exported using the current new version of Cocos Studio 2.3.2), the execution interrupt stops at the next line of the Addarmaturefileinfo call.

After part of the source code tracking, I tried to use the shredding technology to generate the CSB file, as far as possible to the cpp-tests provided by the form of the same, the results are not even!

Too bad, I just want to use armature and the corresponding technology as follows:

Armature->getanimation ()->setmovementeventcallfunc (Cc_callback_0 (testanimationevent::animationevent, this , std::p laceholders::_1, std::p laceholders::_2, std::p laceholders::_3));

But, unfortunately, can only despair! Without armature, we simply cannot use the Setmovementeventcallfunc callback function and its corresponding technology.

Unfortunately, for the above questions, the official website and the demo did not mention!

Workaround

For the above requirements in my current program, I can only try other workarounds, because my requirements are not high. So I tried to use the frame event method to solve the above problem.

Here, I paste the relevant code in my example game.

The first part is as follows:

2load title and mushroom animation node* node2 = Csloader::createnode ("SPLASHANIMATIONSKELETON.CSB"); AddChild (Node2); Node2->setposition (VEC2 (Visiblerect::center (). x, Visiblerect::center (). y)); In the Cocos Studio designer, choose whether or not to loop playback, for the animation in the code whether the loop play no effect!!! actiontimeline* Action2 = Csloader::createtimeline ("SPLASHANIMATIONSKELETON.CSB"); Node2->runaction (Action2); Action2->gotoframeandplay (0,false); Action2->setframeeventcallfunc (Cc_callback_1 (splashscene::onframeevent, this));

Note that the SPLASHANIMATIONSKELETON.CSB above is a simple skeletal animation file created using Cocos Studio 2.3.2.

I originally designed the use of the Setmovementeventcallfunc method to combine the armature data to achieve the goal is: when the bone animation playback end, triggering another established event, and in this event to complete another animation play task.

For these goals, it should be possible to use frame events, just a little more hassle. For example, you need to fill in the frame event data in the studio designer, but you can finally implement it.

Another part of the relevant code is as follows:

Void splashscene::onframeevent (frame* frame) { eventframe* evnt = dynamic_cast <EventFrame*> (frame); if  (!evnt)   return; std::string str =  Evnt->getevent (); if  (str ==  "Lastframe")  {  node* butterfly_01  = csloader::createnode ("BUTTERFLYARMATURE_01.CSB");   addchild (butterfly_01,100);   butterfly_01->setposition (VEC2 (Visiblerect::right () x + 100, 0));   Actiontimeline* action2 = csloader::createtimeline ("BUTTERFLYARMATURE_01.CSB");   Butterfly_01->runaction (Action2);   action2->gotoframeandplay (0, true);   Node*  p1 = _rootlayer->getchildbyname ("Mushroom_point");   auto  action =  sequence::create (   moveto::create (2, p1->getposition ()),    Callfunc::create (Cc_callback_0 (splashscene::cAllback0, this),    nullptr);   butterfly_01->runaction (action);  }} 

As you can see, I'm judging by the frame event callback function that triggers another butterfly to fly into the animation when the animation plays to a specific frame (exactly the first animation I asked for at the end of the play).

A recap

Through the Study and research section Cocos2d-x and Cocos Studio The latest version of the technology can learn more excellent development technology, at the same time, destined to sacrifice a lot of time to "tread the pit", maybe there is lost it.

Finally, to remind the novice classmate, the Code section in the sample project and the Resource data file section are somewhat ambiguous calls, of course, it seems that the official is to use the latest C + + code to use (or protect) the resources exported by early studio. But at the same time, but revealed a lot of haste to "slip".

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

Cocos2d-x 3.8.1 The Skeletal animation loading method Addarmaturefileinfo still has problems

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.