利用Cocostudio动画编辑器导出资源播放动画

前端之家收集整理的这篇文章主要介绍了利用Cocostudio动画编辑器导出资源播放动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<1>

  1. #ifndef __Eliminate__AnimationSprite__
  2. #define __Eliminate__AnimationSprite__
  3.  
  4. #include <stdio.h>
  5. #include "cocos2d.h"
  6. #include "cocostudio/CocoStudio.h"
  7.  
  8. USING_NS_CC;
  9. using namespace std;
  10. using namespace cocostudio;
  11.  
  12. //----------
  13. ///普通的动物
  14. //----------
  15.  
  16. typedef enum {
  17. DISPLAY_MODE_NORMAL = 0,//正常
  18. DISPLAY_MODE_HORIZONTAL,//消除所在列的精灵
  19. DISPLAY_MODE_VERTICAL,//消除所在行的精灵
  20. DISPLAY_MODE_TL,//t、l型
  21. DISPLAY_MODE_OVERFIVE,//五个以上消除
  22. DISPLAY_MODE_CENTER,//十字型
  23. DISPLAY_MODE_FF,//向外扩散一个格
  24. DISPLAY_MODE_HHH,//三列
  25. DISPLAY_MODE_VVV,//三行
  26. DISPLAY_MODE_CRYSTAL //结晶 --jn新增
  27. } DisplayMode;
  28.  
  29.  
  30. class AnimationSprite:public Armature
  31. {
  32. public:
  33. AnimationSprite(int row,int col,int imgIndex);
  34. static AnimationSprite *create(const std::string& name,int row,int imgIndex);
  35. void playAnimation(string name);
  36. CC_SYNTHESIZE(int,m_row,Row); //列
  37. CC_SYNTHESIZE(int,m_col,Col); //行
  38. CC_SYNTHESIZE(int,m_imgIndex,ImgIndex); //标记索引
  39. CC_SYNTHESIZE(int,m_score,score);
  40. CC_SYNTHESIZE(bool,m_isNeedRemove,IsNeedRemove); //是否需要移除
  41. CC_SYNTHESIZE(bool,m_ignoreCheck,IgnoreCheck);
  42. CC_SYNTHESIZE(bool,m_isTouchEable,IsTouchEable);
  43. CC_SYNTHESIZE(bool,m_isSpecial,IsSpecial); //标记是否是通过特殊元素交换形成的特殊元素
  44. //CC_SYNTHESIZE(DisplayMode,m_displayMode,DisplayMode);
  45. CC_PROPERTY(DisplayMode,DisplayMode); //--jn新增
  46. CC_SYNTHESIZE(bool,m_isNeedToPlayEffect,IsNeedToPlayEffect);
  47. void setOverFiveImg();
  48. private:
  49. Armature* _armatureHeng; //横消动画
  50. Armature* _armatureShu; //竖消动画
  51. };
  52. #endif /* defined(__Eliminate__AnimationSprite__) */
  1. #include "AnimationSprite.h"
  2. #include "DataConfig.h"
  3. #include "BasicInclude.h"
  4.  
  5. AnimationSprite::AnimationSprite(int row,int imgIndex)
  6. {
  7. ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/xiongmao_Animation0.png","Animals/xiongmao_Animation0.plist","Animals/xiongmao_Animation.ExportJson");
  8. ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/tuzi_Animation0.png","Animals/tuzi_Animation0.plist","Animals/tuzi_Animation.ExportJson");
  9. ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/qingwa_Animation0.png","Animals/qingwa_Animation0.plist","Animals/qingwa_Animation.ExportJson");
  10. ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/qie_Animation0.png","Animals/qie_Animation0.plist","Animals/qie_Animation.ExportJson");
  11. ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/laohu_Animation0.png","Animals/laohu_Animation0.plist","Animals/laohu_Animation.ExportJson");
  12. ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/huliAnimation0.png","Animals/huliAnimation0.plist","Animals/huliAnimation.ExportJson");
  13. ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/zusNewAnimation0.png","Animals/zusNewAnimation0.plist","Animals/zusNewAnimation.ExportJson");
  14. this->m_row = row;
  15. this->m_col = col;
  16. this->m_imgIndex = imgIndex;
  17. this->m_score = 5;
  18. this->m_isNeedRemove = false;
  19. this->m_ignoreCheck = false;
  20. this->m_isTouchEable = false;
  21. this->m_isSpecial = false;
  22. this->m_displayMode = DISPLAY_MODE_NORMAL;
  23. _armatureHeng = NULL;
  24. _armatureShu = NULL;
  25. m_isNeedToPlayEffect = true;
  26. }
  27.  
  28. AnimationSprite *AnimationSprite::create(const std::string& name,int imgIndex)
  29. {
  30. AnimationSprite *armature = new AnimationSprite(row,col,imgIndex);
  31. if (armature && armature->init(name))
  32. {
  33. armature->autorelease();
  34. return armature;
  35. }
  36. CC_SAFE_DELETE(armature);
  37. return nullptr;
  38. }
  39.  
  40. void AnimationSprite::playAnimation(string name)
  41. {
  42. if(this->getAnimation()){
  43. this->getAnimation()->play(name);
  44. }else{
  45. log("<<<animation 不可为空!!! AnimationSprite::playAnimation");
  46. }
  47. }
  48.  
  49. void AnimationSprite::setDisplayMode(DisplayMode var){
  50. m_displayMode = var;
  51. ArmatureDataManager::getInstance()->addArmatureFileInfo("SpecialEffect/teshudaoju_NewAnimation0.png","SpecialEffect/teshudaoju_NewAnimation0.plist","SpecialEffect/teshudaoju_NewAnimation.ExportJson");
  52. if(m_displayMode != DISPLAY_MODE_NORMAL){
  53. playAudio(siwuxiaoEffect);
  54. }
  55. if(m_displayMode == DISPLAY_MODE_HORIZONTAL){
  56. if(!_armatureShu){
  57. _armatureShu = Armature::create("teshudaoju_NewAnimation");
  58. _armatureShu->getAnimation()->play("zongxiang");
  59. this->addChild(_armatureShu,100);
  60. log("Anchorpoint,x: %f,y:%f",_armatureShu->getAnchorPoint().x,_armatureShu->getAnchorPoint().y);
  61. }
  62. }else if (m_displayMode == DISPLAY_MODE_VERTICAL){
  63. if(!_armatureHeng){
  64. _armatureHeng = Armature::create("teshudaoju_NewAnimation");
  65. _armatureHeng->getAnimation()->play("hengxiang");
  66. this->addChild(_armatureHeng,101);
  67. }
  68. }else if(m_displayMode == DISPLAY_MODE_TL){ //TL的特效目前还没有
  69. if(!_armatureShu){
  70. _armatureShu = Armature::create("teshudaoju_NewAnimation");
  71. _armatureShu->getAnimation()->play("zongxiang");
  72. this->addChild(_armatureShu,100);
  73. _armatureHeng = Armature::create("teshudaoju_NewAnimation");
  74. _armatureHeng->getAnimation()->play("hengxiang");
  75. this->addChild(_armatureHeng,101);
  76. }
  77. }else if (m_displayMode == DISPLAY_MODE_OVERFIVE){
  78. // setOverFiveImg();
  79. // log("<<<fengche");
  80. }
  81. }
  82.  
  83. DisplayMode AnimationSprite::getDisplayMode(){
  84. return m_displayMode;
  85. }
  86.  
  87. void AnimationSprite::setOverFiveImg(){
  88. // playAnimation("fengche"); //这样时不行的。。。在这添加一个动画的特效还差不多
  89. }
<2>
  1. ArmatureDataManager::getInstance()->addArmatureFileInfo("menu/startMenu/zhujiemian_Animation0.png","menu/startMenu/zhujiemian_Animation0.plist","menu/startMenu/zhujiemian_Animation.ExportJson");
  1. Armature *armatureSun = Armature::create("zhujiemian2_Animation");
  2. armatureSun->setPosition(winSize.width / 2,winSize.height / 2);
  3. armatureSun->getAnimation()->playWithIndex(0);
  4. armatureSun->setScale(winScaleMin); //----jn
  5. this->addChild(armatureSun,-1);
  6. armatureSun->getAnimation()->setMovementEventCallFunc(this,movementEvent_selector(StartScene::movementCallback));


  1. void StartScene::movementCallback(Armature * armature,MovementEventType type,const std::string& movementID){
  2. if (type == COMPLETE)
  3. {
  4. if (strcmp(movementID.c_str(),"guang") == 0)
  5. {
  6. armature->getAnimation()->playWithIndex(1,1,1);
  7. }
  8. }
  9. }


<3>
  1. Armature *armature = Armature::create("teshudaoju_NewAnimation"); //锤子爆破特效 --jn新增
  2. armature->setPosition(point);
  3. armature->getAnimation()->play("chuizi");
  4. m_spLayer->addChild(armature,10);
  5. removeArmature(armature);
  1. void GameScene::removeArmature(Node *node)
  2. {
  3. Armature *armature = (Armature *)node;
  4. if (armature) {
  5. armature->getAnimation()->setMovementEventCallFunc(this,movementEvent_selector(GameScene::movementCallback));
  6. }
  7. }

  1. #pragma mark 将动画移除
  2. void GameScene::movementCallback(Armature * armature,const std::string& movementID)
  3. {
  4. if (type == COMPLETE)
  5. {
  6. armature->removeFromParent();
  7. }
  8. }

猜你在找的Cocos2d-x相关文章