Browse Source

Allow tweens with 0 duration

Thomas Dy 11 years ago
parent
commit
4ea9800ed3
1 changed files with 13 additions and 5 deletions
  1. 13 5
      scripts/util.js

+ 13 - 5
scripts/util.js

@@ -133,17 +133,25 @@ function SimpleTween(duration, start, end, easing) {
   this.deferred = Q.defer();
   this.timer = 0;
   this.promise = this.deferred.promise;
+  if(this.duration == 0) {
+    this.deferred.resolve();
+  }
 };
 
 SimpleTween.prototype = new BaseTween();
 
 SimpleTween.prototype.update = function(dt) {
-  this.timer += dt;
-  if(this.timer >= this.duration) {
-    this.timer = this.duration;
-    this.deferred.resolve();
+  if(this.duration > 0) {
+    this.timer += dt;
+    if(this.timer >= this.duration) {
+      this.timer = this.duration;
+      this.deferred.resolve();
+    }
+    this.value = this.easing(this.timer, this.start, this.end, this.duration);
+  }
+  else {
+    this.value = this.end;
   }
-  this.value = this.easing(this.timer, this.start, this.end, this.duration);
 };
 
 function PromiseTween(value, promise) {