首页 > 其他 > 详细

cocos3.0使用cocostudio动画帧结合地图对象键值创建精灵动画

时间:2014-06-17 15:20:46      阅读:403      评论:0      收藏:0      [点我收藏+]

内容例如以下:

 

#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);


 

bubuko.com,布布扣

 

 

 

cocos3.0使用cocostudio动画帧结合地图对象键值创建精灵动画,布布扣,bubuko.com

cocos3.0使用cocostudio动画帧结合地图对象键值创建精灵动画

原文:http://www.cnblogs.com/zfyouxi/p/3792425.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!