Skip frames when minimum frame rate is not reached
The new minFrameRate option is used to make sure that an animation does not run longer than the time calculated from that frame rate. Time is made up by skipping frames, i.e. skipping execution of the eachStep callback.
This commit is contained in:
@@ -52,6 +52,22 @@ OpenLayers.Tween = OpenLayers.Class({
|
||||
*/
|
||||
time: null,
|
||||
|
||||
/**
|
||||
* APIProperty: minFrameRate
|
||||
* {Number} The minimum framerate for animations. After each step, the time
|
||||
* spent in the animation is compared to the calculated time at this frame
|
||||
* rate. If the animation runs longer than the calculated time, the next
|
||||
* step is skipped.
|
||||
*/
|
||||
minFrameRate: 30,
|
||||
|
||||
/**
|
||||
* Property: startTime
|
||||
* {Number} The timestamp of the first execution step. Used for skipping
|
||||
* frames
|
||||
*/
|
||||
startTime: null,
|
||||
|
||||
/**
|
||||
* Property: animationId
|
||||
* {int} Loop id returned by OpenLayers.Animation.start
|
||||
@@ -92,6 +108,7 @@ OpenLayers.Tween = OpenLayers.Class({
|
||||
this.duration = duration;
|
||||
this.callbacks = options.callbacks;
|
||||
this.time = 0;
|
||||
this.startTime = new Date().getTime();
|
||||
OpenLayers.Animation.stop(this.animationId);
|
||||
this.animationId = null;
|
||||
if (this.callbacks && this.callbacks.start) {
|
||||
@@ -139,7 +156,10 @@ OpenLayers.Tween = OpenLayers.Class({
|
||||
this.time++;
|
||||
|
||||
if (this.callbacks && this.callbacks.eachStep) {
|
||||
this.callbacks.eachStep.call(this, value);
|
||||
// skip frames if frame rate drops below threshold
|
||||
if ((new Date().getTime() - this.startTime) / this.time <= 1000 / this.minFrameRate) {
|
||||
this.callbacks.eachStep.call(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.time > this.duration) {
|
||||
|
||||
Reference in New Issue
Block a user