Cocos2d-x动画工具类
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动画工具类的更多相关文章
- Android两个页面之间的切换效果工具类
import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; ...
- 实用工具类--第三方开源--Lazy
下载地址 :https://github.com/ddwhan0123/Lazy 工具 描述 AnimationUtils 动画工具类 AppUtils APP相关信息工具类 AssetDatabas ...
- iOS开发--QQ音乐练习,旋转动画的实现,音乐工具类的封装,定时器的使用技巧,SliderBar的事件处理
一.旋转动画的实现 二.音乐工具类的封装 -- 返回所有歌曲,返回当前播放歌曲,设置当前播放歌曲,返回下一首歌曲,返回上一首歌曲方法的实现 头文件 .m文件 #import "ChaosMu ...
- Android开源项目大全 - 工具类
主要包括那些不错的开发库,包括依赖注入框架.图片缓存.网络相关.数据库ORM建模.Android公共库.Android 高版本向低版本兼容.多媒体相关及其他. 一.依赖注入DI 通过依赖注入减少Vie ...
- Android 开源控件与常用开发框架开发工具类
Android的加载动画AVLoadingIndicatorView 项目地址: https://github.com/81813780/AVLoadingIndicatorView 首先,在 bui ...
- Android快捷便利但不常被使用的原生工具类
Android快捷便利但不常被使用的原生工具类 Android SDK原生 API中,有一些常用的工具类,运用得当可以省事省力省时,何况还是Android官方提供的,现在收集整理一些出来.DateUt ...
- Android 常见工具类封装
1,MD5工具类: public class MD5Util { public final static String MD5(String s) { char hexDigits[] = { '0' ...
- 自己封装的工具类,使用原生SwipeRefreshLayout+RecycleView实现下拉刷新和加载更多
实现SwipeRefreshLayout+RecycleView实现刷新 在你的xml文件里写上如下代码: <android.support.v4.widget.SwipeRefreshLayo ...
- 拍照、本地图片工具类(兼容至Android7.0)
拍照.本地图片工具类:解决了4.4以上剪裁会提示"找不到文件"和6.0动态授予权限,及7.0报FileUriExposedException异常问题. package com.hb ...
随机推荐
- Realm Swift
Realm Swift 当前这个翻译,主要是方便我自己查阅api,有非常多地方写的比較晦涩或者没有翻译,敬请谅解 version 0.98.7 官方文档 參考文献 Realm支持类型 String,N ...
- 一次真实的蓝屏分析 ntkrnlmp.exe
故事背景: 话说我一直都是远程公司的电脑,在我晚上11点敲代码敲得正爽的时候,被远程的主机挂掉了,毫无征兆的挂掉了,我特么还好有闲着没事就ctrl + s保存代码的习惯,要不然白敲了那么久,我以为是公 ...
- ZH奶酪:Windows7+VirtualBox安装Ubuntu虚拟机问题总结
1.下载VirtualBox(我的是4.3.26版本) https://www.virtualbox.org/ 2.下载Ubuntu ISO文件(我的是ubuntu-14.04-desktop-amd ...
- 1z0-052 q209_11
11: Your database instance is started using the server parameter file (SPFILE). You executed a comma ...
- Eclipse Source not found
Eclipse debug模式下找不到Java源文件 CreateTime--2018年3月19日10:43:39 Author:Marydon 与MyEclipse不同,每次Eclipse导入新 ...
- 迅雷极速版|xunlei下载
迅雷很不错的下载软件,曾经出现了,迷你版.极速版... 迅雷极速版 迅雷精简版 迅雷极速版-下载: http://pan.baidu.com/s/1dF3XYTj 密码: 5tj3 迅雷精简版-下载: ...
- bootstrap之UpdateStrings
UpdateStrings package io.appium.android.bootstrap.handler; import io.appium.android.bootstrap.Androi ...
- 【centos6.5 安装 node.js + npm】
1.参考链接:http://www.jb51.net/article/116231.htm 2.下载的nodejs版本一定要是v0.12.10的(传送门:https://nodejs.org/en/b ...
- 如何使php页面中不再出现NOTICE和DEPRECATED的错误提示
在php.ini配置文件中修改: error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED 亲测有效,拿去用吧
- 利用ASP.NET一般处理程序动态生成Web图像(转)
摘自:http://www.cnblogs.com/zhouhb/archive/2011/02/15/1955262.html 一般处理程序的扩展名为ashx,它实现了IHttpHandler接口, ...