Load bone animation resources in Cocos2d-x

Source: Internet
Author: User
Tags touch
before we talk about skeletal animation, let's look at the editor for creating bone animations Cocos Studio

Cocos Studio is a set of free game development tools based on cocos2d-x that can help developers quickly create game resources, use the editor for most tedious game development work, and further help game developers reduce development cycles and improve development efficiency.

Cocos Studio itself is not only designed for the editing of skeletal animations, it also provides editing of information such as UI, scenes, and data. For the current Cocos studio, there are two main points, one is the win version of Cocos Studio and the other is the Mac version Cocos Studio v1.0 ALPHA1, which was just released shortly. The former consists of the UI editor, motion editor, Scene editor and data editor, which are used to deal with the UI, animation resources, game scenes and game data in the game. and the Mac version of Cocos Studio integrates the original UI and animation editor, making it more free for small partners. For a more clear understanding of the Skeleton animation editor, you can find it online. so next we'll show you how to load a skeletal animation resource using the Cocos Studio animation in the Cocos2d-x program, you first need to include the relevant header file, as follows

#include "cocostudio/cocostudio.h"

using namespace Cocostudio;


Create a skeleton animation object, you need to load the animation files and resource files into the program. Here we load the animation by Armaturemanager the animation data Manager. Armaturemanager itself is a singleton, which manages the armature in the entire scene. The armature, however, encapsulates the animation we need to play the animation. This shows that this is a three-tier hierarchy. Which armaturemanager the largest, then armature, and finally animation.

Armaturedatamanager::getinstance ()

Addarmaturefileinfo ("xxx. Exportjson "," Xxx.plist "," xxx.png ");//three kinds of files

armature* am1=armature::create ("xxx"); Create an Animated object

AM1, Settag (110);


Am1->getanimation ()->play ("Walk")//Play animation Walk is just one of them this->addchild (AM1);


The animation needs to be played according to the specific needs in order to know which animation the user wants to play. You can specify the animation name to play the animation like the code above, or you can play the animation by specifying an action number, as follows:

Am1->getanimation ()->playwithindex (0);//Play the first set of animations

Set the callback function for the animation

Am1->getanimation ()->setmovementeventcallfunc ([] (armature *ani, Movementeventtype tp,const std::string & Name) {

if (tp==movementeventtype::complete) {

Cclog ("tp%d,name:%s", Tp,name.c_str ());//can output detect a


Under

if (strcmp (Name.c_str (), "attack") ==0)//attack Another set of animations in the file


{

Am1->getanimation ()->play ("Walk");

}

}

});


Post-Touch Transform action

Auto Lis=eventlistenertouchonebyone::create ();

Lis->ontouchbegan=[&] (touch* t,event *e) {

Armature *am2= (armature *) This->getchildbytag (110);//Because in the function I need to pass the number to get the object created above

Am2->getanimation ()->play ("Stand"); Standing animation in a file

Director::getinstance ()->geteventdispatcher ()

->addeventlistenerwithscenegraphpriority (LIS, this);

Original link: http://blog.csdn.net/qq_31301099/article/details/49668179

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.