Skip to content

Commit 048bf1f

Browse files
committed
Merge pull request cocos2d#2981 from WenhaiLin/v3-animate-getcurrframeindex2
Add Animate:getCurrentFrameIndex
2 parents 04de140 + af78839 commit 048bf1f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cocos2d/actions/CCActionInterval.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,7 +3263,8 @@ cc.Animate = cc.ActionInterval.extend(/** @lends cc.Animate# */{
32633263
_nextFrame:0,
32643264
_origFrame:null,
32653265
_executedLoops:0,
3266-
_splitTimes:null,
3266+
_splitTimes: null,
3267+
_currFrameIndex:0,
32673268

32683269
/**
32693270
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
@@ -3291,6 +3292,14 @@ cc.Animate = cc.ActionInterval.extend(/** @lends cc.Animate# */{
32913292
this._animation = animation;
32923293
},
32933294

3295+
/**
3296+
* Gets the index of sprite frame currently displayed.
3297+
* @return {Number}
3298+
*/
3299+
getCurrentFrameIndex: function () {
3300+
return this._currFrameIndex;
3301+
},
3302+
32943303
/**
32953304
* @param {cc.Animation} animation
32963305
* @return {Boolean}
@@ -3373,7 +3382,8 @@ cc.Animate = cc.ActionInterval.extend(/** @lends cc.Animate# */{
33733382
var numberOfFrames = frames.length, locSplitTimes = this._splitTimes;
33743383
for (var i = this._nextFrame; i < numberOfFrames; i++) {
33753384
if (locSplitTimes[i] <= dt) {
3376-
this.target.setSpriteFrame(frames[i].getSpriteFrame());
3385+
_currFrameIndex = i;
3386+
this.target.setSpriteFrame(frames[_currFrameIndex].getSpriteFrame());
33773387
this._nextFrame = i + 1;
33783388
} else {
33793389
// Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS

0 commit comments

Comments
 (0)