Cocos2dx 2.2.1 use of skeleton Animation

Source: Internet
Author: User

Use bone Animation:

// Load the resource file. PNG Image, plist file, and exportjson animation file. Generally, this resource can be loaded at the beginning of the scenario.

Ccarmaturedatamanager: sharedarmaturedatamanager ()-> addarmaturefileinfo ("restest/hero. exportjson ");

Ccarmature * _ parrmature = ccarmature: Create ("hero ");

_ Parrmature-> getanimation ()-> play ("walk"); // sets the index of the currently running animation. Multiple animations can be created in one "project ".

_ Parrmature-> getanimation ()-> setspeedscale (0.1f); // modify the playback speed of the skeleton animation.

_ Parrmature-> getanimation ()-> setframeeventcallfunc (this, frameevent_selector (loadinggongshilayer: onframeevent); // Add a key frame callback function for the skeleton Animation

_ Parrmature-> getanimation ()-> setmovementeventcallfunc (this, movementevent_selector (loadinggongshilayer: animationevent); // Add a callback function for a skeleton animation Action event

This-> addchild (_ parrmature );

// Void identifier: animationevent (ccarmature * armature, movementeventtype movementtype, const char * movementid) {STD: String id = movementid; ccsize size = ccdirector :: shareddirector ()-> getwinsize (); If (movementtype = loop_complete) {If (ID. compare ("walk") = 0) {cclog ("skeleton animation walking ends ");}}}
// Key frame void loadinggongshilayer: onframeevent (bone * bone, const char * EVT, int originframeindex, int currentframeindex) {If (strcmp (EVT, "100") = 0) {cclog ("Responding to events ");}}

2. Skeleton animation attributes

String A = _ parrmature-> getanimation ()-> getcurrentmovementid (); // get the currently played animation int q = _ parrmature-> getanimation ()-> getcurrentframeindex (); // get the current frame

Ccarmature * m_parmature = ccarmature: Create (_ parrmature-> getname (). c_str (); // create a new skeleton Animation 2

M_parmature-> getanimation ()-> play (A. c_str (); // play an action that is being played by skeleton Animation 2

M_parmature-> getanimation ()-> gotoandplay (Q); // play skeleton Animation 2 play skeleton Animation 1 play Frame

3. Add a particle effect to a skeleton of the skeleton animation.

// Set the particle
Ccparticlesystem * P1 = ccparticlesystemquad: Create ("resparticles/dr_gongji_bingjian_hd.plist"); // create a bone ccbone * Bone = cocos2d: Extension: ccbone :: create ("p1 ");
// Add the particle effect bone-> adddisplay (P1, 0); bone-> changedisplaybyindex (0, true); bone-> setignoremovementbonedata (true ); bone-> setzorder (100); bone-> setscale (1.2f); _ parrmature-> addbone (bone, "Wuqi "); // "Wuqi" indicates the name of the skeleton in the skeleton 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.