cocos2d-x帧动画实现(续)
2011-11-17 20:03
363 查看
猴子原创, 欢迎转载,转载请在明显处注明! 谢谢。
原文地址:http://blog.csdn.net/yanghuiliu/article/details/6933421
之前我介绍过cocos2d-x的帧动画实现,今天我把帧动画详细写一下。
帧动画就是很多张png的序列图实现轮流播放产生动画效果。
那么首先我们要一套动画的序列图,没有图的可以看引擎例子里面的图。很多张图我们可以采用TP工具将它们压缩到一张png里面去,这样程序只需要读取一次就行了,提高效率。
![](http://hi.csdn.net/attachment/201111/3/0_132032178337K4.gif)
比如我将这里的6张图压成了一个png,TP会产生一个所有图的png和一个plist描述文件,plist很像xml,它描述了每一张图的位置,大小等信息。程序就是通过plist文件在合成的大png里面找到每一张图的。
合成的大图叫fei.png,对应的fei.plist。
里面的小图。叫 飞0001.png、飞0002.png、.........、飞0006.png
下面开始程序的创建
view plain
//创建cache
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
char strPlist[64] = {0};
char strPng[64] = {0};
sprintf(strPlist,"fei.plist");
//sprintf(strPng,"fei.pvr.ccz");
sprintf(strPng,"fei.png");
cache->addSpriteFramesWithFile(strPlist, strPng);
//创建动画每一帧,从cache里面读取
CCMutableArray<CCSpriteFrame*>* animFrames = new CCMutableArray<CCSpriteFrame*>(6);
char str[64] = {0};
for(int i = 1; i <= 6; i++)
{
sprintf(str, "飞%04d.png", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames->addObject(frame);
}
CCAnimation* animation = CCAnimation::animationWithFrames(animFrames,0.04f);
CCRepeatForever* mFly=CCRepeatForever::actionWithAction( CCAnimate::actionWithAnimation(animation, false));
animFrames->release();
cache->removeSpriteFramesFromFile(strPlist);
这里的mFly就是一个创建好的action。当然它是可以重复播放的。你要是只想播放一次。
那么替换成
CCActionInterval* mFly=CCAnimate::actionWithAnimation(animation,true);
你可能看到了我里面注释了一行代码,就是我不是压缩成了png,而是压缩成了pvr.ccz。这种格式效率更高。
pvr是苹果自己支持的图片格式,但是比较占内存,压缩成ccz后就很小了。用法一样。
原文地址:http://blog.csdn.net/yanghuiliu/article/details/6933421
之前我介绍过cocos2d-x的帧动画实现,今天我把帧动画详细写一下。
帧动画就是很多张png的序列图实现轮流播放产生动画效果。
那么首先我们要一套动画的序列图,没有图的可以看引擎例子里面的图。很多张图我们可以采用TP工具将它们压缩到一张png里面去,这样程序只需要读取一次就行了,提高效率。
![](http://hi.csdn.net/attachment/201111/3/0_132032178337K4.gif)
比如我将这里的6张图压成了一个png,TP会产生一个所有图的png和一个plist描述文件,plist很像xml,它描述了每一张图的位置,大小等信息。程序就是通过plist文件在合成的大png里面找到每一张图的。
合成的大图叫fei.png,对应的fei.plist。
里面的小图。叫 飞0001.png、飞0002.png、.........、飞0006.png
下面开始程序的创建
view plain
//创建cache
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
char strPlist[64] = {0};
char strPng[64] = {0};
sprintf(strPlist,"fei.plist");
//sprintf(strPng,"fei.pvr.ccz");
sprintf(strPng,"fei.png");
cache->addSpriteFramesWithFile(strPlist, strPng);
//创建动画每一帧,从cache里面读取
CCMutableArray<CCSpriteFrame*>* animFrames = new CCMutableArray<CCSpriteFrame*>(6);
char str[64] = {0};
for(int i = 1; i <= 6; i++)
{
sprintf(str, "飞%04d.png", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames->addObject(frame);
}
CCAnimation* animation = CCAnimation::animationWithFrames(animFrames,0.04f);
CCRepeatForever* mFly=CCRepeatForever::actionWithAction( CCAnimate::actionWithAnimation(animation, false));
animFrames->release();
cache->removeSpriteFramesFromFile(strPlist);
这里的mFly就是一个创建好的action。当然它是可以重复播放的。你要是只想播放一次。
那么替换成
CCActionInterval* mFly=CCAnimate::actionWithAnimation(animation,true);
你可能看到了我里面注释了一行代码,就是我不是压缩成了png,而是压缩成了pvr.ccz。这种格式效率更高。
pvr是苹果自己支持的图片格式,但是比较占内存,压缩成ccz后就很小了。用法一样。
相关文章推荐
- cocos2d-x帧动画实现(续)
- cocos2d-x帧动画实现(写下备忘)
- cocos2d-x帧动画实现(写下备忘)
- cocos2d-x帧动画实现(续)
- cocos2d-x帧动画实现(续)
- cocos2d-x帧动画实现(续)
- cocos2d中如何使用图片纹理图集的加载来实现一个动画的功能
- cocos2d中sprite动画接口及动画实现思路总结
- 跑酷类游戏------quick-cocos2d-x 加载英雄与其动画到界面具体实现(一)
- cocos2d-x CCAnimation实现动画
- cocos2d from python Animation 动画的实现
- cocos2d-js 2048带动画实现
- cocos2d-x实现多个精灵动画同步播放(二)
- 【iphone游戏开发】iphone-Cocos2d游戏开发之四:精灵实现缩放,旋转,跳动,移动等动画
- cocos2d-x-2.x与3.x帧动画实现方式的改变
- cocos2d-x 使用action实现各种动画效果
- 在COCOS2D-X中使用DRAGONBONES实现骨骼动画
- COCOS2D-X之帧动画的一种实现Demo
- 在cocos2d-x中使用DragonBones实现骨骼动画
- Cocos2D游戏之旅(五):三种方法实现技能动画