1.此工具类的目的是为了方便运行动画。使用TexturePackerGUI工具能够导出plist文件和png图片,这里我演示样例图片叫bxjg.plist和bxjg.png

//////////////////////////////////////.h文件

#ifndef _AnimateUtil_H_

#define _AnimateUtil_H_

#include "cocos2d.h"

using namespace cocos2d;

using namespace std;

class AnimateUtil//动画工具类

{

public:

//依据文件名称字前缀创建动画对象                         名称   播放的间隔    是否循环播放   

static Animation * createWithSingleFrameName(const char * name, float delay, int Loops);

//依据文件名称字前缀创建动画对象,指定动绘图片数量        名称    图片数量  播放的间隔  是否循环播放 

static Animation * createWithFrameNameAndNum(const char * name, int num, float delay, int Loops);

};

#endif

/////////////////////////////////.cpp文件

#include "AnimateUtil.h"





Animation * AnimateUtil::createWithSingleFrameName(const char * name, float delay, int Loops)

{

/*将图片载入到精灵帧缓冲池*/

SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();

Vector<SpriteFrame * > frameVec;

SpriteFrame * frame = NULL;

int index = 1;//小图片数量

do 

{

//从SpriteFrame缓冲池获取SpriteFrame对象

frame = frameCache->getSpriteFrameByName(StringUtils::format("%s%d.png", name, index++));

//不断获取spriteFrame对象,直到获取的值为NULL

if (frame == NULL)

{

break;

}

frameVec.pushBack(frame);

} while (true);

//使用SpiteFrame列表创建动画对象

Animation * animation = Animation::createWithSpriteFrames(frameVec);

animation->setLoops(Loops);//设置是否循环

animation->setRestoreOriginalFrame(true);

animation->setDelayPerUnit(delay);//设置动画间隙

return animation;

}





Animation * AnimateUtil::createWithFrameNameAndNum(const char * name, int num, float delay, int Loops)

{

SpriteFrameCache * frameCache = SpriteFrameCache::getInstance();





SpriteFrame * frame = NULL;

Vector<SpriteFrame *> frameVec;

int index = 1;

for (int  i = 1; i <= num; i++)

{

frame = frameCache->getSpriteFrameByName(StringUtils::format("%s%d.png", name, index++));

if (frame ==NULL)

{

break;

}

frameVec.pushBack(frame);

}

Animation * animation = Animation::createWithSpriteFrames(frameVec);

animation->setLoops(Loops);

animation->setRestoreOriginalFrame(true);

animation->setDelayPerUnit(delay);

return animation;

}

Cocos2d-x动画工具类的更多相关文章

  1. Android两个页面之间的切换效果工具类

    import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; ...

  2. 实用工具类--第三方开源--Lazy

    下载地址 :https://github.com/ddwhan0123/Lazy 工具 描述 AnimationUtils 动画工具类 AppUtils APP相关信息工具类 AssetDatabas ...

  3. iOS开发--QQ音乐练习,旋转动画的实现,音乐工具类的封装,定时器的使用技巧,SliderBar的事件处理

    一.旋转动画的实现 二.音乐工具类的封装 -- 返回所有歌曲,返回当前播放歌曲,设置当前播放歌曲,返回下一首歌曲,返回上一首歌曲方法的实现 头文件 .m文件 #import "ChaosMu ...

  4. Android开源项目大全 - 工具类

    主要包括那些不错的开发库,包括依赖注入框架.图片缓存.网络相关.数据库ORM建模.Android公共库.Android 高版本向低版本兼容.多媒体相关及其他. 一.依赖注入DI 通过依赖注入减少Vie ...

  5. Android 开源控件与常用开发框架开发工具类

    Android的加载动画AVLoadingIndicatorView 项目地址: https://github.com/81813780/AVLoadingIndicatorView 首先,在 bui ...

  6. Android快捷便利但不常被使用的原生工具类

    Android快捷便利但不常被使用的原生工具类 Android SDK原生 API中,有一些常用的工具类,运用得当可以省事省力省时,何况还是Android官方提供的,现在收集整理一些出来.DateUt ...

  7. Android 常见工具类封装

    1,MD5工具类: public class MD5Util { public final static String MD5(String s) { char hexDigits[] = { '0' ...

  8. 自己封装的工具类,使用原生SwipeRefreshLayout+RecycleView实现下拉刷新和加载更多

    实现SwipeRefreshLayout+RecycleView实现刷新 在你的xml文件里写上如下代码: <android.support.v4.widget.SwipeRefreshLayo ...

  9. 拍照、本地图片工具类(兼容至Android7.0)

    拍照.本地图片工具类:解决了4.4以上剪裁会提示"找不到文件"和6.0动态授予权限,及7.0报FileUriExposedException异常问题. package com.hb ...

随机推荐

  1. [Javascript] Closure Cove, Common mistake

    They’ve got a problem with their existing code, which tries to use a closure. Check it out: function ...

  2. 能说明你的Javascript技术很烂的五个原因

    Javascript在互联网上名声很臭,但你又很难再找到一个像它这样如此动态.如此被广泛使用.如此根植于我们的生活中的另外一种语言.它的低学习门槛让很多人都称它为学前脚本语言,它另外一个让人嘲笑的东西 ...

  3. 微信小程序 - 自定义tabbar

    更新: 2019-1-18:自定义tabbar组件已发布 各种奇葩的需求,造就了我们 wxml <view class="nav-tabs"> <view cla ...

  4. 算法笔记_188:历届试题 危险系数(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 抗日战争时期,冀中平原的地道战曾发挥重要作用. 地道的多个站点间有通道连接,形成了庞大的网络.但也有隐患,当敌人发现了某个站点后,其它站点 ...

  5. 解决 maven 项目启动 提示 class not find

    第一种方法: 项目 --> .classpath <classpathentry exported="true" kind="con" path=& ...

  6. MVC时间对比及时间范围判断

    方法一:使用DateTime.Compare 方法 public static int Compare( DateTime t1, DateTime t2 ) t1 早于 t2:小于零t1 与 t2  ...

  7. vs2010支持html5+css3

    第一步. 先到微软官方下载一个 Microsoft Visual Studio 2010 sp1 . 给传送门:下载 下载到这个东东 ---

  8. C# winform 安装服务

    一.知识点 1.安装服务 installutil HardwareScanService.exe //安装服务 sc config HardwareScanService type= interact ...

  9. 关于highstock横坐标的一些的一些说明(1)使用UTC时间

    highstock的数据格式采用的是[[时间,数据],[时间,数据],[时间,数据],[时间,数据]],而时间采用的是13位的毫秒值,如[1133136000000,69.66],采用的时间格式为UT ...

  10. mysql优化之参数优化

    1.优化方式 硬件优化=>系统优化=>mysql配置优化=>SCHEMA优化=>sql优化=>其他解决方案(redis or MongoDB or Cassandra o ...