zoukankan      html  css  js  c++  java
  • 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);


     

  • 相关阅读:
    ubuntu進入dos界面命令 ubuntu進入圖形界面命令
    CentOS 8.2远程连接vncserver升级后1.10.1无法启动解决记录
    Eclipse:Cannot complete the install because of a conflicting dependency.问题解决
    Android SDK更新以及ADT更新出现问题的解决办法
    Visual Studio 2013开启JavaScript的智能提示功能
    linux中mysql密码找回的两种方式
    Oracle 物化视图 说明
    linux下mysql字符集编码问题的修改
    mysql 启动错误-server PID file could not be found
    在linux安装mysql,并设置远程访问
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/3792425.html
Copyright © 2011-2022 走看看