<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__) */
<2>
- #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"); //这样时不行的。。。在这添加一个动画的特效还差不多
- }
- 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);
- }
- }
- }
- 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();
- }
- }