Skeleton animation weapon replacement effect Demo of COCOS2D-X

Source: Internet
Author: User

The effect of our Demo is to click the screen to change the weapon. character dress-up should be a common requirement in the game, so write this Demo to share it with the people who need it. i. We directly add code in the HelloCpp project of the COCOS2D-X. we add the following code to the initialization: [cpp] CCSize szWin = CCDirector ctor: sharedDirector ()-> getVisibleSize (); CCArmatureDataManager: Alert ()-> addArmatureFileInfo ("knight.png ", "knight. plist "," knight. xml "); // load the skeleton animation file CCArmatureDataManager: sharedArmatureDataManager ()-> addArmatureFileInfo (" weapon.png "," weapon. plist "," weapon. xml "); // load the skeleton animation file setTouchEnabled (true); // enable the 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-sword4.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);} II. Since we use classes in extensions in the COCOS2D-X, therefore, you need to add the corresponding directory, corresponding header files, and lib files. ①. Choose project> Properties> Configuration Properties> VC ++ directory> include directory to add the extensions folder path.: $ (SolutionDir) \ extensions ②. Add the header file, namespace, and library files involved as follows: [cpp] # include "CCArmature/utils/CCArmatureDataManager. h "# include" CCArmature/CCArmature. h "# pragma comment (lib," libBox2d. lib ") # pragma comment (lib," libExtensions. lib ") using namespace extension; 3. register the touch screen distributor [cpp] void TestUseMutiplePicture: Pull () {CCDirector: shareddire()-> getTouchDispatcher ()-> addTargetedDelegate (this, 0, true);} 3. responds to the touch screen event to implement the update. the Code is as follows: [cpp] bool HelloWorld: ccTouchBegan (CCTouch * pTouch, CCEvent * pEvent) {static int nDisplayIndex =-1; ++ nDisplayIndex; nDisplayIndex = (nDisplayIndex) % 5; pArmature-> getBone ("weapon")-> changeDisplayByIndex (nDisplayIndex, true); return false ;}

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.