1 goog.provide('lime.animation.Sequence'); 2 3 4 goog.require('goog.math.Coordinate'); 5 goog.require('lime.Sprite'); 6 goog.require('lime.animation.Animation'); 7 8 /** 9 * Sequence of animations that are run after each other. 10 * Also accepts more than two animations 11 * @param {Array.<lime.animation.Animation>|lime.animation.Animation} one First animation. 12 * @param {lime.animation.Animation=} opt_two Second animation. 13 * @constructor 14 * @extends lime.animation.Animation 15 */ 16 lime.animation.Sequence = function(one, opt_two) { 17 18 lime.animation.Animation.call(this); 19 20 var act = goog.array.toArray(arguments); 21 if (goog.isArray(one)) act = one; 22 23 if (act.length > 2) { 24 25 var first = act.shift(); 26 this.actions = [first, new lime.animation.Sequence(act)]; 27 28 } 29 else { 30 this.actions = act; 31 } 32 33 this.setDuration(this.actions[0].duration_ + this.actions[1].duration_); 34 35 }; 36 goog.inherits(lime.animation.Sequence, lime.animation.Animation); 37 38 /** 39 * @inheritDoc 40 * @see lime.animation.Animation#initTarget 41 */ 42 lime.animation.Sequence.prototype.initTarget = function(target) { 43 lime.animation.Animation.prototype.initTarget.call(this, target); 44 45 this.setDuration(this.actions[0].duration_ + this.actions[1].duration_); 46 this.split_ = this.actions[0].duration_ / this.duration_; 47 this.last_ = -1; 48 }; 49 50 /** 51 * @inheritDoc 52 * @see lime.animation.Animation#stop 53 */ 54 lime.animation.Sequence.prototype.stop = function() { 55 if (this.last_ != -1) { 56 this.actions[this.last_].stop(this.targets); 57 } 58 lime.animation.Animation.prototype.stop.apply(this, arguments); 59 }; 60 61 /** 62 * @inheritDoc 63 * @see lime.animation.Animation#updateAll 64 */ 65 lime.animation.Sequence.prototype.updateAll = function(t,targets) { 66 if (this.status_ == 0) return t; 67 68 var i = targets.length; 69 while (--i >= 0) { 70 this.getTargetProp(targets[i]); 71 } 72 73 var found = 0, 74 new_t = 0; 75 76 if (t >= this.split_) { 77 found = 1; 78 if (this.split_ == 1) new_t = 1; 79 else new_t = (t - this.split_) / (1 - this.split_); 80 } 81 else { 82 found = 0; 83 if (this.split_ != 0) new_t = t / this.split_; 84 else new_t = 1; 85 } 86 87 if (this.last_ == -1 && found == 1) { 88 this.actions[0].status_ = 1; 89 //this.actions[0].initTarget(target); 90 this.actions[0].updateAll(1, targets); 91 this.actions[0].stop(); 92 } 93 94 if (this.last_ != found) { 95 if (this.last_ != -1) { 96 this.actions[this.last_].updateAll(1, targets); 97 this.actions[this.last_].stop(); 98 } 99 this.actions[found].status_ = 1; 100 //this.actions[found].initTarget(target); 101 } 102 103 this.actions[found].updateAll(new_t, targets); 104 this.last_ = found; 105 106 return t; 107 }; 108 109 /** 110 * @inheritDoc 111 * @see lime.animation.Animation#reverse 112 */ 113 lime.animation.Sequence.prototype.reverse = function() { 114 return new lime.animation.Sequence(this.actions[1].reverse(), 115 this.actions[0].reverse()); 116 }; 117