微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

<1>

#ifndef __Eliminate__Animationsprite__
#define __Eliminate__Animationsprite__

#include <stdio.h>
#include "cocos2d.h"
#include "cocostudio/CocoStudio.h"

USING_NS_CC;
using namespace std;
using namespace cocostudio;

//----------
///普通的动物
//----------

typedef enum {
    disPLAY_MODE_norMAL = 0,//正常
    disPLAY_MODE_HORIZONTAL,//消除所在列的精灵
    disPLAY_MODE_VERTICAL,//消除所在行的精灵
    disPLAY_MODE_TL,//t、l型
    disPLAY_MODE_OVERFIVE,//五个以上消除
    disPLAY_MODE_CENTER,//十字型
    disPLAY_MODE_FF,//向外扩散一个disPLAY_MODE_HHH,//三列
    disPLAY_MODE_VVV,//三行
    disPLAY_MODE_CRYSTAL      //结晶  --jn新增
} displayMode;


class Animationsprite:public Armature
{
public:
    Animationsprite(int row,int col,int imgIndex);
    
    static Animationsprite *create(const std::string& name,int row,int imgIndex);
    
    void playAnimation(string name);
    
    CC_SYNTHESIZE(int,m_row,Row); //列
    CC_SYNTHESIZE(int,m_col,Col); //行
    CC_SYNTHESIZE(int,m_imgIndex,ImgIndex); //标记索引
    CC_SYNTHESIZE(int,m_score,score);
    CC_SYNTHESIZE(bool,m_isNeedRemove,IsNeedRemove); //是否需要移除
    CC_SYNTHESIZE(bool,m_ignoreCheck,IgnoreCheck);
    CC_SYNTHESIZE(bool,m_isTouchEable,IsTouchEable);
    CC_SYNTHESIZE(bool,m_isspecial,Isspecial); //标记是否是通过特殊元素交换形成的特殊元素
    //CC_SYNTHESIZE(displayMode,m_displayMode,displayMode);
    CC_PROPERTY(displayMode,displayMode);  //--jn新增
    
    CC_SYNTHESIZE(bool,m_isNeedToPlayEffect,IsNeedToPlayEffect);
    
    void setoverFiveImg();
private:
    Armature* _armatureHeng;   //横消动画
    Armature* _armatureShu;    //竖消动画
};
#endif /* defined(__Eliminate__Animationsprite__) */
#include "Animationsprite.h"
#include "DataConfig.h"
#include "BasicInclude.h"

Animationsprite::Animationsprite(int row,int imgIndex)
{
    
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/xiongmao_Animation0.png","Animals/xiongmao_Animation0.plist","Animals/xiongmao_Animation.ExportJson");
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/tuzi_Animation0.png","Animals/tuzi_Animation0.plist","Animals/tuzi_Animation.ExportJson");
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/qingwa_Animation0.png","Animals/qingwa_Animation0.plist","Animals/qingwa_Animation.ExportJson");
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/qie_Animation0.png","Animals/qie_Animation0.plist","Animals/qie_Animation.ExportJson");
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/laohu_Animation0.png","Animals/laohu_Animation0.plist","Animals/laohu_Animation.ExportJson");
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/huliAnimation0.png","Animals/huliAnimation0.plist","Animals/huliAnimation.ExportJson");
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Animals/zusNewAnimation0.png","Animals/zusNewAnimation0.plist","Animals/zusNewAnimation.ExportJson");
    
    this->m_row = row;
    this->m_col = col;
    this->m_imgIndex = imgIndex;
    this->m_score = 5;
    this->m_isNeedRemove = false; 
    this->m_ignoreCheck = false;
    this->m_isTouchEable = false;
    this->m_isspecial = false;
    this->m_displayMode = disPLAY_MODE_norMAL;
    
    _armatureHeng = NULL;
    _armatureShu = NULL;
    
    m_isNeedToPlayEffect = true;
}

Animationsprite *Animationsprite::create(const std::string& name,int imgIndex)
{
    Animationsprite *armature = new Animationsprite(row,col,imgIndex);
    if (armature && armature->init(name))
    {
        armature->autorelease();
        return armature;
    }
    CC_SAFE_DELETE(armature);
    return nullptr;
}

void Animationsprite::playAnimation(string name)
{
    if(this->getAnimation()){
        this->getAnimation()->play(name);
    }else{
        log("<<<animation 不可为空!!! Animationsprite::playAnimation");
    }
}

void Animationsprite::setdisplayMode(displayMode var){
    m_displayMode = var;
    
    ArmatureDataManager::getInstance()->addArmatureFileInfo("SpecialEffect/teshudaoju_NewAnimation0.png","SpecialEffect/teshudaoju_NewAnimation0.plist","SpecialEffect/teshudaoju_NewAnimation.ExportJson");
    
    
    if(m_displayMode != disPLAY_MODE_norMAL){
        playAudio(siwuxiaoEffect);
    }
    
    if(m_displayMode == disPLAY_MODE_HORIZONTAL){
        
        if(!_armatureShu){
            _armatureShu = Armature::create("teshudaoju_NewAnimation");
            _armatureShu->getAnimation()->play("zongxiang");
            this->addChild(_armatureShu,100);
            
            log("Anchorpoint,x: %f,y:%f",_armatureShu->getAnchorPoint().x,_armatureShu->getAnchorPoint().y);
        }
    }else if (m_displayMode == disPLAY_MODE_VERTICAL){
        
        if(!_armatureHeng){
            _armatureHeng = Armature::create("teshudaoju_NewAnimation");
            _armatureHeng->getAnimation()->play("hengxiang");
            this->addChild(_armatureHeng,101);
        }
    }else if(m_displayMode == disPLAY_MODE_TL){ //TL的特效目前还没有
        
        if(!_armatureShu){
            _armatureShu = Armature::create("teshudaoju_NewAnimation");
            _armatureShu->getAnimation()->play("zongxiang");
            this->addChild(_armatureShu,100);
            
            _armatureHeng = Armature::create("teshudaoju_NewAnimation");
            _armatureHeng->getAnimation()->play("hengxiang");
            this->addChild(_armatureHeng,101);
            
        }
        
    }else if (m_displayMode == disPLAY_MODE_OVERFIVE){
//        setoverFiveImg();
//        log("<<<fengche");
    }
}

displayMode Animationsprite::getdisplayMode(){
    return m_displayMode;
}

void Animationsprite::setoverFiveImg(){
//    playAnimation("fengche");  //这样时不行的。。。在这添加一个动画的特效还差不多
}
<2>
ArmatureDataManager::getInstance()->addArmatureFileInfo("menu/startmenu/zhujiemian_Animation0.png","menu/startmenu/zhujiemian_Animation0.plist","menu/startmenu/zhujiemian_Animation.ExportJson");
Armature *armatureSun = Armature::create("zhujiemian2_Animation");
armatureSun->setPosition(winSize.width / 2,winSize.height / 2);
armatureSun->getAnimation()->playWithIndex(0);
armatureSun->setScale(winScaleMin); //----jn
this->addChild(armatureSun,-1); 
armatureSun->getAnimation()->setMovementEventCallFunc(this,movementEvent_selector(StartScene::movementCallback));


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


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

#pragma mark 将动画移除
void GameScene::movementCallback(Armature * armature,const std::string& movementID)
{
    if (type == COMPLETE)
    {
        armature->removeFromParent();
    }
}

原文地址:https://www.jb51.cc/cocos2dx/342982.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐