Cocos2d-x Skeleton Animation Weapon Dressup effect demo

Source: Internet
Author: User
Tags touch

The effect of our demo is to click on the screen to achieve the replacement of weapons. Character Dressup should be a very common requirement in the game, so write this demo to share it with the people who need it.

First, we directly in the Cocos2d-x bring the Hellocpp project to add code can. We add the following code to the initialization:

 Ccsize Szwin = Ccdirector::shareddirector ()->getvisiblesize (); Ccarmaturedatamanager::sharedarmaturedatamanager ()->addarmaturefileinfo ("Knight.png", "Knight.plist", "
 Knight.xml "); Ccarmaturedatamanager::sharedarmaturedatamanager ()->addarmaturefileinfo ("Weapon.png", "Weapon.plist", "
 Weapon.xml ");
 Settouchenabled (TRUE);//Turn on touch screen response parmature = ccarmature::create ("Knight_f/knight"); Parmature->getanimation ()->playbyindex (0);//Play The First Action Parmature->setposition (CCP (szwin.width/2-100,
 SZWIN.HEIGHT/2));
 Parmature->setscale (1.5f);
 This->addchild (parmature); std::string sweaponname[] = {"Weapon_f-sword.png", "Weapon_f-sword2.png", "Weapon_f-sword3.png", "Weapon_f-sword
 4.png "," Weapon_f-sword5.png "};
 Ccspritedisplaydata Sprdisplaydata; for (int i=0;i<sizeof (sweaponname)/sizeof (sweaponname[0]), i++) {Sprdisplaydata.setparam (Sweaponname[i].c_str ()
  );
 Parmature->getbone ("Weapon")->adddisplay (&sprdisplaydata,i); }
Second, because we use the cocos2d-x in the extensions class, it is necessary to add the corresponding directory and the corresponding header file and Lib file

①, the path to add Extensions folder in the Include directory, configuration Properties, properties---->vc++ directory: $ (solutiondir) \extensions
②, add header files, namespaces, and the library files involved are as follows:

#include "cocos-ext.h"
#include "ccarmature/utils/ccarmaturedatamanager.h"
#include "ccarmature/ CCArmature.h "
#pragma  comment (lib," LibBox2d.lib ")
#pragma  comment (lib," LibExtensions.lib ")
using namespace extension;
Third, register the touch screen dispenser and set its priority
void Testusemutiplepicture::registerwithtouchdispatcher ()
{
 ccdirector::shareddirector () Gettouchdispatcher ()->addtargeteddelegate (this,0, True);
}
Third, respond to touch screen events to achieve the facelift. The code is as follows:

BOOL Helloworld::cctouchbegan (Cctouch *ptouch, ccevent *pevent)
{
 static int ndisplayindex  =-1;
 ++ndisplayindex;
 Ndisplayindex = (ndisplayindex)%5;
 Parmature->getbone ("Weapon")->changedisplaybyindex (ndisplayindex,true);
 return false;
}

Four, the program operation effect screenshot. is not feel domineering exposed



V. Supplementary NOTE: Skeletal animation files involved in the program download link http://t.cn/z86kmpg

PS: Because it is basic learning, it does not make too much analysis. Follow-up will have more exciting content, please pay attention to

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.