Cocos3.0 uses cocostudio animation frames in combination with map object key values to create genie animations

Source: Internet
Author: User

The content is as follows:

# Include "cocos2d. h "# include" cocostudio/CocoStudio. h "// tagtypedef enum {catTag = 1 ,}; // cocostudio animation frame tagtypedef enum {cat1_tag = 1001 ,}; class Base: public cocos2d :: layer {public: Base ();~ Base (); // create a void createSpriteInMap (cocos2d: TMXTiledMap * map, const std: string & strObj, int _ tag in the map, const std: string & strJosn, const std: string & _ index, float scale); // create an animated cococostudio: Armature * createArmature (const std :: string & strJosn, const std: string & _ index, float scale); // remove the animation void removeArmature (int _ tag1, int _ tag2 );};


#include "Base.h"USING_NS_CC;using  namespace cocostudio;Base::Base(){}Base::~Base(){}void  Base::createSpriteInMap(TMXTiledMap* map, const std::string& strObj,int _tag, const  std::string&  strJosn, const std::string&  _index, float scale){auto  group  =map->getObjectGroup(strObj);auto& objs   = group->getObjects();for (auto& obj : objs){ValueMap& dict =obj.asValueMap();float x =dict["x"].asFloat();float y =dict["y"].asFloat();    auto  sprite = Sprite::create();sprite->setPosition(Point(x,y));ArmatureDataManager::getInstance()->addArmatureFileInfo(strJosn);Armature *armature = Armature::create(_index);armature->getAnimation()->playWithIndex(0);armature->setScale(scale);switch (_tag){  case  catTag:  sprite->addChild(armature, 2, catWalkTag);  this->addChild(sprite, 2,catTag);}}}cocostudio::Armature*  Base::createArmature(const  std::string&  strJosn, const std::string&  _index, float scale){ArmatureDataManager::getInstance()->addArmatureFileInfo(strJosn);Armature *armature = Armature::create(_index);armature->getAnimation()->playWithIndex(0);armature->setScale(scale);return armature;}void Base::removeArmature(int _tag1,int _tag2){auto sprite =this->getChildByTag(_tag1);sprite->removeChildByTag(_tag2);}


this->createSpriteInMap(myMap, "jlmPoint", 1, "cat/CatWalks/CatWalks.ExportJson", "CatWalks", 0.5f);


Related Article

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.