From af788391eed6941ac565bcaa5d134a215f4474b8 Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Mon, 13 Jul 2015 13:37:40 +0800 Subject: [PATCH] Add Animate:getCurrentFrameIndex --- cocos2d/actions/CCActionInterval.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index c0de823215..525d79e124 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -3263,7 +3263,8 @@ cc.Animate = cc.ActionInterval.extend(/** @lends cc.Animate# */{ _nextFrame:0, _origFrame:null, _executedLoops:0, - _splitTimes:null, + _splitTimes: null, + _currFrameIndex:0, /** * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
@@ -3291,6 +3292,14 @@ cc.Animate = cc.ActionInterval.extend(/** @lends cc.Animate# */{ this._animation = animation; }, + /** + * Gets the index of sprite frame currently displayed. + * @return {Number} + */ + getCurrentFrameIndex: function () { + return this._currFrameIndex; + }, + /** * @param {cc.Animation} animation * @return {Boolean} @@ -3373,7 +3382,8 @@ cc.Animate = cc.ActionInterval.extend(/** @lends cc.Animate# */{ var numberOfFrames = frames.length, locSplitTimes = this._splitTimes; for (var i = this._nextFrame; i < numberOfFrames; i++) { if (locSplitTimes[i] <= dt) { - this.target.setSpriteFrame(frames[i].getSpriteFrame()); + _currFrameIndex = i; + this.target.setSpriteFrame(frames[_currFrameIndex].getSpriteFrame()); this._nextFrame = i + 1; } else { // Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS