Create a new tween. The callback fires immediately with `start` so the * target snaps to the start value on the same frame the tween is created. * * `start` and `end` may be numbers, Vector2 instances, Color instances, or * any object exposing a `lerp(other, percent) => sameTy
(callback, start = 0, end = 1, duration = 1, options = {})
| 49 | * @param {boolean} [options.useRealTime=false] - Advance even when the game is paused (matches Timer's useRealTime) |
| 50 | * @param {boolean} [options.paused=false] - Start in paused state */ |
| 51 | constructor(callback, start = 0, end = 1, duration = 1, options = {}) |
| 52 | { |
| 53 | ASSERT(typeof callback === 'function', 'Tween callback must be a function'); |
| 54 | if (isLerpable(start)) |
| 55 | { |
| 56 | ASSERT(start.constructor === end.constructor, |
| 57 | 'Tween start and end must be the same type'); |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | ASSERT(isNumber(start), 'Tween start must be a number or have a .lerp method'); |
| 62 | ASSERT(isNumber(end), 'Tween end must be a number when start is a number'); |
| 63 | } |
| 64 | ASSERT(isNumber(duration) && duration > 0, 'Tween duration must be > 0'); |
| 65 | |
| 66 | /** @property {function(number|Vector2|Color):void} - Called with the interpolated value each frame */ |
| 67 | this.callback = callback; |
| 68 | /** @property {number|Vector2|Color} - Starting value */ |
| 69 | this.start = start; |
| 70 | /** @property {number|Vector2|Color} - Ending value */ |
| 71 | this.end = end; |
| 72 | /** @property {number} - Total duration in seconds */ |
| 73 | this.duration = duration; |
| 74 | /** @property {number} - Remaining time in seconds (counts down from duration to 0) */ |
| 75 | this.life = duration; |
| 76 | /** @property {function(number):number} - Easing curve mapping [0,1] -> [0,1] */ |
| 77 | this.ease = options.ease || Ease.LINEAR; |
| 78 | /** @property {boolean} - If true, advance even when the game is paused */ |
| 79 | this.useRealTime = !!options.useRealTime; |
| 80 | /** @property {boolean} - If true, stop advancing until cleared */ |
| 81 | this.paused = !!options.paused; |
| 82 | |
| 83 | /** @private completion callback set by then(), loop(), pingPong(). */ |
| 84 | this.thenCallback = undefined; |
| 85 | /** @private remaining iterations including the current run (loop/pingPong only). */ |
| 86 | this.loopRemaining = 0; |
| 87 | |
| 88 | tweenActive.push(this); |
| 89 | // Snap target to start immediately. |
| 90 | callback(this.interp(duration)); |
| 91 | } |
| 92 | |
| 93 | /** Set the easing curve and return this for chaining. |
| 94 | * @param {function(number):number} easeFn |
nothing calls this directly
no test coverage detected