_setInterval for Sprite

This commit is contained in:
Лаврёнов Антон 2014-02-25 07:30:10 +08:00
parent 0a664e009c
commit 6b8fff082e

View File

@ -61,15 +61,12 @@
this.frameIndex(0); this.frameIndex(0);
}); });
// smooth change for frameRate // smooth change for frameRate
var that = this;
this.on('frameRateChange.kinetic', function() { this.on('frameRateChange.kinetic', function() {
if (!this.anim.isRunning()) { if (!this.anim.isRunning()) {
return; return;
} }
clearInterval(this.interval); clearInterval(this.interval);
this.interval = setInterval(function() { this._setInterval();
that._updateIndex();
}, 1000 / this.getFrameRate());
}); });
this.sceneFunc(this._sceneFunc); this.sceneFunc(this._sceneFunc);
@ -106,13 +103,18 @@
_useBufferCanvas: function() { _useBufferCanvas: function() {
return (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && this.hasStroke(); return (this.hasShadow() || this.getAbsoluteOpacity() !== 1) && this.hasStroke();
}, },
_setInterval: function() {
var that = this;
this.interval = setInterval(function() {
that._updateIndex();
}, 1000 / this.getFrameRate());
},
/** /**
* start sprite animation * start sprite animation
* @method * @method
* @memberof Kinetic.Sprite.prototype * @memberof Kinetic.Sprite.prototype
*/ */
start: function() { start: function() {
var that = this;
var layer = this.getLayer(); var layer = this.getLayer();
/* /*
@ -122,11 +124,7 @@
* redraw * redraw
*/ */
this.anim.setLayers(layer); this.anim.setLayers(layer);
this._setInterval();
this.interval = setInterval(function() {
that._updateIndex();
}, 1000 / this.getFrameRate());
this.anim.start(); this.anim.start();
}, },
/** /**