resize animation duration on the fly

This commit is contained in:
javi 2013-10-10 17:13:00 +02:00
parent 483923c79a
commit fe4c589dc9

View File

@ -27,10 +27,8 @@
loop: true loop: true
}); });
this.domainInv = torque.math.linear(this.options.animationDelay, this.options.animationDelay + this.options.animationDuration); this.rescale();
this.domain = this.domainInv.invert();
this.range = torque.math.linear(0, this.options.steps);
this.rangeInv = this.range.invert();
} }
@ -43,7 +41,13 @@
stop: function() { stop: function() {
this.pause(); this.pause();
this._time = 0; this.time(0);
},
// real animation time
time: function(_) {
if (!arguments.length) return this._time;
this._time = _;
var t = this.range(this.domain(this._time)); var t = this.range(this.domain(this._time));
this.callback(t); this.callback(t);
}, },
@ -56,6 +60,24 @@
} }
}, },
rescale: function() {
this.domainInv = torque.math.linear(this.options.animationDelay, this.options.animationDelay + this.options.animationDuration);
this.domain = this.domainInv.invert();
this.range = torque.math.linear(0, this.options.steps);
this.rangeInv = this.range.invert();
return this;
},
duration: function(_) {
if (!arguments.length) return this.options.animationDuration;
this.options.animationDuration = _;
this.rescale();
if (this.time() > _) {
this.time(0);
}
return this;
},
step: function(s) { step: function(s) {
if(arguments.length === 0) return this.range(this.domain(this._time)); if(arguments.length === 0) return this.range(this.domain(this._time));
this._time = this.domainInv(this.rangeInv(s)); this._time = this.domainInv(this.rangeInv(s));
@ -74,9 +96,8 @@
delta = Math.min(this.options.maxDelta, delta); delta = Math.min(this.options.maxDelta, delta);
this._t0 = t1; this._t0 = t1;
this._time += delta; this._time += delta;
var t = this.range(this.domain(this._time)); this.time(this._time);
this.callback(t); if(this.step() >= this.options.steps) {
if(t >= this.options.steps) {
this._time = 0; this._time = 0;
} }
if(this.running) { if(this.running) {