cocos3.0使用cocostudio動畫幀結合map對象鍵值創建精靈動畫

tags:    時間:2014-05-04 18:58:39
cocos3.0使用cocostudio動畫幀結合地圖對象鍵值創建精靈動畫

內容如下:

 

#include "cocos2d.h" #include "cocostudio/CocoStudio.h" //精靈貓和其他精靈的tag typedef  enum{ 	  catTag =1, };  //cocostudio 動畫幀tag typedef  enum{  	catWalkTag = 1001, };   class Base :public  cocos2d::Layer { public: 	Base(); 	~Base();  	//在地圖中創建一個活多個空精靈節點 	void createSpriteInMap(cocos2d::TMXTiledMap* map, const std::string& strObj,int _tag, const  std::string&  strJosn, const std::string&  _index, float scale); 	    //創建精靈的動畫 	cocostudio::Armature*  createArmature(const  std::string&  strJosn, const std::string&  _index, float scale);  	//移除動畫 	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);


 

 

 

 

推薦閱讀文章

Bookmark the permalink ,來源:互聯網