码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-05-02 05:08:11      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:blog   class   code   get   int   string   

内容如下:

 

#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动画帧结合地图对象键值创建精灵动画

标签:blog   class   code   get   int   string   

原文地址:http://blog.csdn.net/u010296979/article/details/24852125

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!