http://blog.csdn.net/cocos2der/article/details/8728443
http://www.it165.net/pro/html/201405/13204.html
可以通过继承Animate类获得里面的nextFrame变量来知道当前播放到了第几帧:
class MAnimate:public cocos2d::Animate { public: /**当前播放到第几帧*/ int currentFrame = -1; public: static MAnimate* create(Animation *animation); virtual void update(float t); }; MAnimate* MAnimate::create(Animation *animation) { MAnimate *animate = new MAnimate(); animate->initWithAnimation(animation); animate->autorelease(); return animate; } void MAnimate::update(float t) { Animate::update(t); if (this->_nextFrame != this->currentFrame + 1){ this->currentFrame = this->_nextFrame - 1; //log("currentFrame:%d", this->currentFrame); } }
帧动画相关博文:
十分详细介绍的
http://zengrong.net/post/2006.htm
最后,我来解答一下CCAnimationFrame类中的成员变量m_fDelayUnits的。这个变量其实是无用的!!!!
http://www.cnblogs.com/sevenyuan/archive/2013/07/01/3165153.html
Cocos2d-x 2.0 之Actions “三板斧”之一
http://blog.csdn.net/honghaier/article/details/8197892
Cocos2d-x3.0模版容器详解之一:cocos2d::Vector
Cocos2d-x3.0模版容器详解之二:cocos2d::Map
Cocos2d-x3.0模版容器详解之三:cocos2d::Value http://www.cocoachina.com/bbs/read.php?tid=200034
一、帧动画
你可以通过一系列图片文件,像如下这样,创建一个动画:
[cpp]
CCAnimation *animation = CCAnimation::create();
//从本地文件系统中加载图片文件到CCSpriteFrame中区,然后添加到CCAnimation中
for (int i = 1; i < 15; i++)
{
char szImageFileName[128] = {0};
sprintf(szImageFileName, "Images/grossini_dance_%02d.png", i);
animation->addSpriteFrameWithFileName(szImageFileName);
}
animation->setDelayPerUnit(2.8f / 14.0f); // 这个动画包含14帧,将会持续2.8秒.
animation->setRestoreOriginalFrame(true); // 14帧播放完之后返回到第一帧
CCAnimate *action = CCAnimate::create(animation);
sprite->runAction(action); // 运行精灵对象