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

来源:未知 责任编辑:责任编辑 发表时间:2014-05-26 10:56 点击:

内容如下:

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


\

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • cocos2d-x学习笔记(19)--label 、label atlas
    • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
    • Cocos2d-x学习(一):HelloWorld
    • cocos2dx在xcode下开发,编译到android上(2)
    • cocos2d 设置屏幕默认方向
    • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
    • Cocos2d-x 2.0 之 Actions “三板斧” 之一
    • cocos2d-x学习笔记(18)--游戏打包(windows平台)
    • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1