cocos2d-x 一图多帧 取得当前帧的解决方案
来源:互联网 发布:广州多益网络官网 编辑:程序博客网 时间:2024/05/07 13:54
转载请保留此文:
http://blog.csdn.net/xuzhuang2008/article/details/8934645
关于cocos2d-x使用cocostudio也好 其他的动画编辑器也好 生成的plist文件和png文件
通过一图多帧的方式 进行动画的播放
cocos2d-x没有取得当前帧的方法 我也不想修改源代码
参考网上的一些做法
如 取得texture的name等 都不适合一图多帧
这里是我想出的一个办法 大致的思路是这样的
在将帧放入frames的时候 保存这些帧的坐标
然后 在需要的时候 取得sprite的displayframe的个体Rect 这样 你就有2个rect
遍历对比 通过rect的origin.x和y来比较是否相同
这里是具体的实现片段
动画的播放部分
//动画播放部分 CCRect rects[8];CCSprite *flowSprite;CCAnimate *animate;CCSpriteFrame *frame1;CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("texiao0.plist","texiao0.png");CCArray*frames=CCArray::create();char pngName[20];//动画有多少帧 这里的i的大小就是多少for (int i=0;i<8; i++) {sprintf(pngName, "fire\\hotwindg%02d.png",i+1);CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pngName);CCRect rec1 = frame->getRect();rects[i] = rec1;frames->addObject(frame);}//生成CCAnimation对象 CCAnimation* animation =CCAnimation::createWithSpriteFrames(frames,0.06f);CCAnimationCache::sharedAnimationCache()->addAnimation(animation,"aa");CCAnimationCache * aniCache = CCAnimationCache::sharedAnimationCache();CCAnimation* normal = aniCache->animationByName("aa");frames->release();animate = CCAnimate::create(normal);CCFiniteTimeAction *seq = CCSequence::create(animate,NULL);flowSprite = CCSprite::create();animate->setTag(20);flowSprite->autorelease();frame1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("fire\\hotwindg01.png");flowSprite->setDisplayFrame(frame1);flowSprite->setScale(0.3f);addChild(flowSprite,160);flowSprite->runAction(CCRepeatForever::create(animate));flowSprite->setPosition(ccp(200,200));CCLog("%d",animate->getAnimation()->getFrames()->count());
获取部分
int currentAnimIndex = 0; const float EPSINON = 0.000001f;int count = 8;for(int i = 0; i < count; i++) { CCRect rect2 = flowSprite->displayFrame()->getRect();float y = rect2.origin.y - rects[i].origin.y ;float x = rect2.origin.x - rects[i].origin.x ;if (((x >= - EPSINON) && (x <= EPSINON)) && ((y >= - EPSINON) && (y <= EPSINON))){//这个i返回的只是一个索引,如果帧数是从1开始计算就要+1 currentAnimIndex = i+1; } }CCLog("current frame is %d",currentAnimIndex);
- cocos2d-x 一图多帧 取得当前帧的解决方案
- 取得当前鼠标的X,Y坐标
- 取得当前鼠标的X,Y坐标
- 取得当前鼠标的X,Y坐标
- 取得当前鼠标的X,Y坐标
- Cocos2d-x的多分辨率解决方案
- Cocos2d-x的多分辨率解决方案
- COCOS2D-X的create_project.py 错误解决方案
- cocos2d-x的一些问题与解决方案
- cocos2d-x scoket 解决方案
- cocos2d-x scoket 解决方案
- [寒江孤叶丶的Cocos2d-x之旅_18]Cocos2d-x 3.x arm64错误的解决方案
- cocos2d-x 获取当前时间
- cocos2d-x 获取当前时间
- cocos2d-x里得到当前动画播放帧数的方法
- cocos2d-x获取当前动画是第几帧
- cocos2d-x获取当前动画是第几帧
- 关于cocos2d-x 手游lua文件加密的解决方案,cocos2d-x lua
- 一起学mini2440裸机开发(七)--UART高级实验,可变参函数
- 三分算法
- VC日志类log调试信息输出
- opencv支持多种流行视频格式文件的读取
- HDU1428(BFS+DFS+记忆化搜索)
- cocos2d-x 一图多帧 取得当前帧的解决方案
- Linux静态库和动态库
- Core Data数据持久性存储基础教程
- Hibernate 高级查询技巧——集合过滤与子查询
- Android异步加载网络图片
- [Silverlight] 如何在Silverlight ActiveX
- hadoop集群常见错误
- hdu1595-find the longest of the shortest
- windows下搭建SVN服务器及配置myeclipse SVN客户端