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.