利用Cocostudio动画编辑器导出资源播放动画
2015-05-19 14:51
477 查看
<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 col, 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, m_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 col, 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 row, int col, 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));
<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));
}
}
#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 col, 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, m_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 col, 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 row, int col, 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, MovementEventType type, const std::string& movementID) { if (type == COMPLETE) { armature->removeFromParent(); } }
相关文章推荐
- 在项目代码中载入cocostudio导出的动画并循环播放
- cocos2d-x 播放 cocostudio导出的帧动画
- CocoStudio1.6UI编辑器动画播放
- cocostudio1.6UI编辑器中动画使用 cocos2dx3.3 播放问题记录
- cocos动画编辑器导出动画在cocos中播放帧对不齐
- 在项目代码中加载cocostudio导出的动画并循环播放
- CocoStudio1.6UI编辑器动画播放
- CocoStudio1.6UI编辑器动画播放----沈大海
- cocos2d3.3不能播放cocostudio导出的粒子动画
- CocoStudio Lua(lua)动画调用 导出的基本动画播放
- 利用资源文件在dephi程序中播放AVI动画的方法
- Cocos2dx3.x 使用cocostudio导出的骨骼动画
- cocos2d-x 2.2 CocoStudio动画和界面编辑器按钮控制以及场景编辑器使用
- 优化cocostudio 导出资源样式
- cocos2d-x JS 利用重复动作实现动画播放(实现倒计时)
- 安卓 利用videoView 播放资源文件 并且全屏播放 适用于闪屏页
- 利用UIImageView连续播放图片动画效果
- TWaver MONO Design中动画的导出与播放
- 利用CocoStudio导出pvr文件的碎图方式
- cocos-js 播放cocostudio制作的帧动画