Comparing version 0.3.9 to 0.3.10
@@ -13,23 +13,23 @@ var TINA = require('./src/index.js'); | ||
var sequence = new TINA.Sequence() | ||
// .add( | ||
// new TINA.Tween(sprites[0], ['x', 'y']) | ||
// .from({ x: 100, y: 300 }) | ||
// .to({ x: 100, y: 100 }, duration) | ||
// .iterations(2) | ||
// .pingpong(true) | ||
// ) | ||
// .add( | ||
// new TINA.Tween(sprites[1], ['x', 'y']) | ||
// .from({ x: 200, y: 300 }) | ||
// .to({ x: 200, y: 100 }, duration) | ||
// .iterations(2) | ||
// .pingpong(true) | ||
// ) | ||
.add( | ||
new TINA.Tween(sprites[0], ['x', 'y']) | ||
.from({ x: 100, y: 300 }) | ||
.to({ x: 100, y: 100 }, duration) | ||
new TINA.Tween(sprites[2], ['y']) | ||
.from({ y: 300 }) | ||
.to({ y: 100 }, duration) | ||
.iterations(2) | ||
.pingpong(true) | ||
) | ||
.add( | ||
new TINA.Tween(sprites[1], ['x', 'y']) | ||
.from({ x: 200, y: 300 }) | ||
.to({ x: 200, y: 100 }, duration + 1) | ||
.iterations(2) | ||
.pingpong(true) | ||
) | ||
.add( | ||
new TINA.Tween(sprites[2], ['x', 'y']) | ||
.from({ x: 300, y: 300 }) | ||
.to({ x: 300, y: 100 }, duration + 2) | ||
.iterations(2) | ||
.pingpong(true) | ||
) | ||
// .addDelay(100) | ||
@@ -45,6 +45,6 @@ .iterations(2) | ||
console.log(t, dt); | ||
console.log(sprites[0]); | ||
console.log(sprites[1]); | ||
// console.log(sprites[0]); | ||
// console.log(sprites[1]); | ||
console.log(sprites[2]); | ||
}); | ||
@@ -5,3 +5,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
},{"./Transition":16,"./TransitionRelative":17,"./easing":20,"./interpolation":23}],2:[function(require,module,exports){ | ||
function BriefExtension(){this._duration=0,this._onComplete=null,this._iterations=1,this._pingpong=!1,this._persist=!1}module.exports=BriefExtension,BriefExtension.prototype.setSpeed=function(t){0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype.onComplete=function(t){return this._onComplete=t,this},BriefExtension.prototype.getDuration=function(){return this._duration*this._iterations/this._speed},BriefExtension.prototype._setDuration=function(t){this._duration=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._extendDuration=function(t){this._duration+=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._getEndTime=function(){return this._speed>0?this._startTime+this.getDuration():this._speed<0?this._startTime:1/0},BriefExtension.prototype._setStartTime=function(t){this._speed>0?this._startTime=t:this._speed<0?this._startTime=t-this.getDuration():this._startTime=1/0},BriefExtension.prototype._getStartTime=function(){return this._speed>0?this._startTime:this._speed<0?this._startTime+this.getDuration():-(1/0)},BriefExtension.prototype._isTimeWithin=function(t){return this._speed>0?this._startTime<t&&t<this._startTime+this.getDuration():this._speed<0?this._startTime+this.getDuration()<t&&t<this._startTime:!0},BriefExtension.prototype._overlaps=function(t,i){return this._speed>0?(this._startTime-i)*(this._startTime+this.getDuration()-t)<=0:this._speed<0?(this._startTime+this.getDuration()-i)*(this._startTime-t)<=0:!0},BriefExtension.prototype.goToEnd=function(){return this.goTo(this.getDuration(),this._iterations-1)},BriefExtension.prototype.loop=function(){return this.iterations(1/0)},BriefExtension.prototype.iterations=function(t){return 0>t?(console.warn("[BriefExtension.iterations] Number of iterations cannot be negative"),this):(this._iterations=t,null!==this._player&&this._player._onPlayableChanged(this),this)},BriefExtension.prototype.persist=function(t){return this._persist=t,this},BriefExtension.prototype.pingpong=function(t){return this._pingpong=t,null!==this._player&&this._player._onPlayableChanged(this),this},BriefExtension.prototype._complete=function(t){return this._persist===!0?(this._startTime+=t,void this._player._onPlayableChanged(this)):this._player._inactivate(this)===!1?this:void(null!==this._onComplete&&this._onComplete(t))},BriefExtension.prototype._moveTo=function(t,i,e){if(i*=this._speed,void 0===e){if(0!==i)if(1===this._iterations)this._time=(t-this._startTime)*this._speed,i>0?this._time>=this._duration&&(e=this._time-this._duration,i-=e,this._time=this._duration):0>i&&this._time<=0&&(e=this._time,i-=e,this._time=0);else{t=(t-this._startTime)*this._speed;var s=t/this._duration;i>0?s<this._iterations?this._time=t%this._duration:(e=(s-this._iterations)*this._duration,i-=e,this._time=this._duration*(1-(Math.ceil(this._iterations)-this._iterations))):0>i&&(s>0?this._time=t%this._duration:(e=s*this._duration,i-=e,this._time=0)),this._pingpong===!0&&(Math.ceil(this._iterations)===this._iterations?void 0===e?0===(1&Math.ceil(s))&&(this._time=this._duration-this._time):1===(1&Math.ceil(s))&&(this._time=this._duration-this._time):0===(1&Math.ceil(s))&&(this._time=this._duration-this._time))}}else i>0?(e=Math.max((t-this._startTime)*this._speed-this._duration*this.iterations,0),this._time=this._duration):(e=Math.min((t-this._startTime)*this._speed,0),this._time=0),i-=e;this._update(i,e),null!==this._onUpdate&&this._onUpdate(this._time,i),void 0!==e&&this._complete(e)}; | ||
function BriefExtension(){this._duration=0,this._onComplete=null,this._iterations=1,this._pingpong=!1,this._persist=!1}module.exports=BriefExtension,BriefExtension.prototype.setSpeed=function(t){0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype.onComplete=function(t){return this._onComplete=t,this},BriefExtension.prototype.getDuration=function(){return this._duration*this._iterations/this._speed},BriefExtension.prototype._setDuration=function(t){this._duration=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._extendDuration=function(t){this._duration+=t,null!==this._player&&this._player._onPlayableChanged(this)},BriefExtension.prototype._getEndTime=function(){return this._speed>0?this._startTime+this.getDuration():this._speed<0?this._startTime:1/0},BriefExtension.prototype._setStartTime=function(t){this._speed>0?this._startTime=t:this._speed<0?this._startTime=t-this.getDuration():this._startTime=1/0},BriefExtension.prototype._getStartTime=function(){return this._speed>0?this._startTime:this._speed<0?this._startTime+this.getDuration():-(1/0)},BriefExtension.prototype._isTimeWithin=function(t){return this._speed>0?this._startTime<t&&t<this._startTime+this.getDuration():this._speed<0?this._startTime+this.getDuration()<t&&t<this._startTime:!0},BriefExtension.prototype._overlaps=function(t,i){return this._speed>0?(this._startTime-i)*(this._startTime+this.getDuration()-t)<=0:this._speed<0?(this._startTime+this.getDuration()-i)*(this._startTime-t)<=0:!0},BriefExtension.prototype.goToEnd=function(){return this.goTo(this.getDuration(),this._iterations-1)},BriefExtension.prototype.loop=function(){return this.iterations(1/0)},BriefExtension.prototype.iterations=function(t){return 0>t?(console.warn("[BriefExtension.iterations] Number of iterations cannot be negative"),this):(this._iterations=t,null!==this._player&&this._player._onPlayableChanged(this),this)},BriefExtension.prototype.persist=function(t){return this._persist=t,this},BriefExtension.prototype.pingpong=function(t){return this._pingpong=t,null!==this._player&&this._player._onPlayableChanged(this),this},BriefExtension.prototype._complete=function(t){return this._persist===!0?(this._startTime+=t,void this._player._onPlayableChanged(this)):this._player._inactivate(this)===!1?this:void(null!==this._onComplete&&this._onComplete(t))};var epsilon=1e-6;BriefExtension.prototype._moveTo=function(t,i,e){i*=this._speed;var s;if(0!==i)if(1===this._iterations)this._time=(t-this._startTime)*this._speed,i>0?this._time>=this._duration?(s=this._time-this._duration,this._time=this._duration):this._time<0:0>i&&this._time<=0&&(s=this._time,this._time=0);else{t=(t-this._startTime)*this._speed;var n=t/this._duration;i>0?n>0&&n<this._iterations?this._time=t%this._duration:(s=(n-this._iterations)*this._duration,this._time=this._duration*(1-(Math.ceil(this._iterations)-this._iterations))):0>i&&(n>0&&n<this._iterations?this._time=t%this._duration:(s=n*this._duration,this._time=0)),this._pingpong===!0&&(void 0===s?0===(1&Math.ceil(n))&&(this._time=this._duration-this._time):Math.ceil(this._iterations)===this._iterations&&0===(1&Math.ceil(this._iterations))&&(this._time=this._duration-this._time))}void 0!==e&&void 0===s&&(i>0&&this.duration-this._time<epsilon?(s=e,this._time=this._duration):0>i&&this._time<epsilon&&(s=e,this._time=0)),this._update(i,s),null!==this._onUpdate&&(void 0===s?this._onUpdate(this._time,i):this._onUpdate(this._time,i-s)),void 0!==s&&this._complete(s)}; | ||
@@ -24,6 +24,6 @@ },{}],3:[function(require,module,exports){ | ||
},{"./AbstractTween":1,"./BriefPlayable":3}],8:[function(require,module,exports){ | ||
function Playable(){this._player=null,this._handle=null,this._startTime=0,this._time=0,this._speed=1,this._onStart=null,this._onPause=null,this._onResume=null,this._onUpdate=null,this._onStop=null}module.exports=Playable,Object.defineProperty(Playable.prototype,"speed",{get:function(){return this._speed},set:function(t){this.setSpeed(t)}}),Object.defineProperty(Playable.prototype,"time",{get:function(){return this._time},set:function(t){this.goTo(t)}}),Playable.prototype.onStart=function(t){return this._onStart=t,this},Playable.prototype.onUpdate=function(t){return this._onUpdate=t,this},Playable.prototype.onStop=function(t){return this._onStop=t,this},Playable.prototype.onPause=function(t){return this._onPause=t,this},Playable.prototype.onResume=function(t){return this._onResume=t,this},Playable.prototype.tweener=function(t){return null===t||void 0===t?(console.warn("[Playable.tweener] Given tweener is invalid:",t),this):(this._player=t,this)},Playable.prototype.setSpeed=function(t){return 0>t?void console.warn("[Playable.speed] This playable cannot have negative speed"):(0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,void(null!==this._player&&this._player._onPlayableChanged(this)))},Playable.prototype.goTo=function(t,e){return 1===this._iterations?0===this._speed?this._startTime+=this._time-t:this._startTime+=(this._time-t)/this._speed:(e=e||0,0===this._speed?this._startTime+=this._time-t-e*this._duration:this._startTime+=(this._time-t-e*this._duration)/this._speed),this._time=t,null!==this._player&&this._player._onPlayableChanged(this),this},Playable.prototype.goToBeginning=function(){return this.goTo(0,0)},Playable.prototype.getDuration=function(){return 1/0},Playable.prototype._getEndTime=function(){return 1/0},Playable.prototype._setStartTime=function(t){this._startTime=t},Playable.prototype._getStartTime=function(){return this._startTime},Playable.prototype._isWithin=function(t){return this._startTime<t},Playable.prototype._overlaps=function(t,e){return(t-this._startTime)*(e-this._startTime)<=0},Playable.prototype.rewind=function(){return this.goTo(0,0),this},Playable.prototype.delay=function(t){return this.start(-t)},Playable.prototype.start=function(t){return null===this._player&&(this._player=TINA._getDefaultTweener()),this._validate()===!1?this:this._player._add(this)===!1?this:((void 0===t||null===t)&&(t=0),this._startTime=this._player._time-t,this)},Playable.prototype._start=function(){null!==this._onStart&&this._onStart()},Playable.prototype.stop=function(){return null===this._player?void console.warn("[Playable.stop] Cannot stop a playable that is not running"):this._player._inactivate(this)===!1?this:(null!==this._onStop&&this._onStop(),this)},Playable.prototype.resume=function(){return this._player._activate(this)===!1?this:(null!==this._onResume&&this._onResume(),this)},Playable.prototype.pause=function(){return this._player._inactivate(this)===!1?this:(null!==this._onPause&&this._onPause(),this)},Playable.prototype._moveTo=function(t,e){e*=this._speed,this._time=(t-this._startTime)*this._speed,this._update(e),null!==this._onUpdate&&this._onUpdate(this._time,e)},Playable.prototype._update=function(){},Playable.prototype._validate=function(){}; | ||
function Playable(){this._player=null,this._handle=null,this._startTime=0,this._time=0,this._speed=1,this._onStart=null,this._onPause=null,this._onResume=null,this._onUpdate=null,this._onStop=null}module.exports=Playable,Object.defineProperty(Playable.prototype,"speed",{get:function(){return this._speed},set:function(t){this.setSpeed(t)}}),Object.defineProperty(Playable.prototype,"time",{get:function(){return this._time},set:function(t){this.goTo(t)}}),Playable.prototype.onStart=function(t){return this._onStart=t,this},Playable.prototype.onUpdate=function(t){return this._onUpdate=t,this},Playable.prototype.onStop=function(t){return this._onStop=t,this},Playable.prototype.onPause=function(t){return this._onPause=t,this},Playable.prototype.onResume=function(t){return this._onResume=t,this},Playable.prototype.tweener=function(t){return null===t||void 0===t?(console.warn("[Playable.tweener] Given tweener is invalid:",t),this):(this._player=t,this)},Playable.prototype.setSpeed=function(t){return 0>t?void console.warn("[Playable.speed] This playable cannot have negative speed"):(0===t?0!==this._speed&&(this._startTime+=this._time/this._speed-this._time):0===this._speed?this._startTime+=this._time-this._time/t:this._startTime+=this._time/this._speed-this._time/t,this._speed=t,void(null!==this._player&&this._player._onPlayableChanged(this)))},Playable.prototype.goTo=function(t,e){return 1===this._iterations?0===this._speed?this._startTime+=this._time-t:this._startTime+=(this._time-t)/this._speed:(e=e||0,0===this._speed?this._startTime+=this._time-t-e*this._duration:this._startTime+=(this._time-t-e*this._duration)/this._speed),this._time=t,null!==this._player&&this._player._onPlayableChanged(this),this},Playable.prototype.goToBeginning=function(){return this.goTo(0,0)},Playable.prototype.getDuration=function(){return 1/0},Playable.prototype._getEndTime=function(){return 1/0},Playable.prototype._setStartTime=function(t){this._startTime=t},Playable.prototype._getStartTime=function(){return this._startTime},Playable.prototype._isWithin=function(t){return this._startTime<t},Playable.prototype._overlaps=function(t,e){return(t-this._startTime)*(e-this._startTime)<=0},Playable.prototype.rewind=function(){return this.goTo(0,0),this},Playable.prototype.delay=function(t){return this.start(-t)},Playable.prototype.start=function(t){return null===this._player&&(this._player=TINA._startDefaultTweener()),this._validate()===!1?this:this._player._add(this)===!1?this:((void 0===t||null===t)&&(t=0),this._startTime=this._player._time-t,this)},Playable.prototype._start=function(){null!==this._onStart&&this._onStart()},Playable.prototype.stop=function(){return null===this._player?void console.warn("[Playable.stop] Trying to stop a playable that was never started."):this._player._remove(this)===!1?this:(null!==this._onStop&&this._onStop(),this)},Playable.prototype.resume=function(){return this._player._activate(this)===!1?this:(null!==this._onResume&&this._onResume(),this)},Playable.prototype.pause=function(){return this._player._remove(this)===!1?this:(null!==this._onPause&&this._onPause(),this)},Playable.prototype._moveTo=function(t,e){e*=this._speed,this._time=(t-this._startTime)*this._speed,this._update(e),null!==this._onUpdate&&this._onUpdate(this._time,e)},Playable.prototype._update=function(){},Playable.prototype._validate=function(){}; | ||
},{}],9:[function(require,module,exports){ | ||
function Player(){Playable.call(this),this._activePlayables=new DoublyList,this._inactivePlayables=new DoublyList,this._playablesToRemove=new DoublyList,this._silent=!1,this._debug=!1}var Playable=require("./Playable"),DoublyList=require("./DoublyList");Player.prototype=Object.create(Playable.prototype),Player.prototype.constructor=Player,module.exports=Player,Player.prototype._add=function(e){return null===e._handle?(e._handle=this._inactivePlayables.add(e),e._player=this,!0):e._handle.container===this._playablesToRemove?(e._handle=this._playablesToRemove.removeByReference(e._handle),!0):e._handle.container===this._activePlayables?(this._warn("[Player._add] Playable is already present, and active"),!1):e._handle.container===this._inactivePlayables?(this._warn("[Player._add] Playable is already present, but inactive (could be starting)"),!1):(this._warn("[Player._add] Playable is used elsewhere"),!1)},Player.prototype._remove=function(e){return null===e._handle?(this._warn("[Player._remove] Playable is not being used"),!1):e._handle.container===this._activePlayables?(e._handle=this._playablesToRemove.add(e._handle),!0):e._handle.container===this._inactivePlayables?(e._handle=this._inactivePlayables.removeByReference(e._handle),!0):e._handle.container===this._playablesToRemove?(this._warn("[Player._remove] Playable is already being removed"),!1):(this._warn("[Player._add] Playable is used elsewhere"),!1)},Player.prototype.remove=function(e){return e._handle.container===this._activePlayables&&e.stop(),this._remove(e),this._onPlayableRemoved(e),this},Player.prototype.removeAll=function(){for(var e=this._activePlayables.first;null!==e;){var a=e.next;e.object.stop(),e=a}return this._handlePlayablesToRemove(),this},Player.prototype.possess=function(e){return null===e._handle?!1:e._handle.container===this._activePlayables||e._handle.container===this._inactivePlayables},Player.prototype._handlePlayablesToRemove=function(){for(;this._playablesToRemove.length>0;){var e=this._playablesToRemove.pop(),a=e.object;a._handle=this._activePlayables.removeByReference(e),a._player=null}0===this._activePlayables.length&&0===this._inactivePlayables.length&&this._onAllPlayablesRemoved()},Player.prototype.clear=function(){return this._activePlayables.clear(),this._inactivePlayables.clear(),this._playablesToRemove.clear(),this._controls.clear(),this},Player.prototype._warn=function(e){this._silent===!1&&console.warn(e),this._debug===!0},Player.prototype.silent=function(e){return this._silent=e,this},Player.prototype.debug=function(e){return this._debug=e,this},Player.prototype.stop=function(){if(null===this._player)return void this._warn("[Player.stop] Cannot stop a player that is not running");for(var e=this._activePlayables.first;null!==e;){var a=e.next,t=e.object;t.stop(),e=a}this._handlePlayablesToRemove(),Playable.prototype.stop.call(this)},Player.prototype._activate=function(e){this._inactivePlayables.removeByReference(e._handle),e._handle=this._activePlayables.addBack(e)},Player.prototype._inactivate=function(e){this._activePlayables.removeByReference(e._handle),e._handle=this._inactivePlayables.addBack(e)},Player.prototype._updatePlayableList=function(e){this._handlePlayablesToRemove();var a,t;e>0?(a=this._time-e,t=this._time):(a=this._time,t=this._time-e);for(var l=this._inactivePlayables.first;null!==l;){var i=l.object;l=l.next,i._overlaps(a,t)&&(this._activate(i),i._start())}},Player.prototype._update=function(e,a){this._updatePlayableList(e);for(var t=this._activePlayables.first;null!==t;t=t.next)t.object._moveTo(this._time,e,a)},Player.prototype._onPlayableChanged=function(){},Player.prototype._onPlayableRemoved=function(){},Player.prototype._onAllPlayablesRemoved=function(){}; | ||
function Player(){Playable.call(this),this._activePlayables=new DoublyList,this._inactivePlayables=new DoublyList,this._playablesToRemove=new DoublyList,this._silent=!0,this._debug=!1}var Playable=require("./Playable"),DoublyList=require("./DoublyList");Player.prototype=Object.create(Playable.prototype),Player.prototype.constructor=Player,module.exports=Player,Player.prototype._add=function(e){return null===e._handle?(e._handle=this._inactivePlayables.add(e),e._player=this,!0):e._handle.container===this._playablesToRemove?(e._handle=this._playablesToRemove.removeByReference(e._handle),!0):e._handle.container===this._activePlayables?(this._warn("[Player._add] Playable is already present, and active"),!1):e._handle.container===this._inactivePlayables?(this._warn("[Player._add] Playable is already present, but inactive (could be starting)"),!1):(this._warn("[Player._add] Playable is used elsewhere"),!1)},Player.prototype._remove=function(e){return null===e._handle?(this._warn("[Player._remove] Playable is not being used"),!1):e._handle.container===this._activePlayables?(e._handle=this._playablesToRemove.add(e._handle),!0):e._handle.container===this._inactivePlayables?(e._handle=this._inactivePlayables.removeByReference(e._handle),!0):e._handle.container===this._playablesToRemove?(this._warn("[Player._remove] Playable is already being removed"),!1):(this._warn("[Player._add] Playable is used elsewhere"),!1)},Player.prototype.remove=function(e){return e._handle.container===this._activePlayables&&e.stop(),this._remove(e),this._onPlayableRemoved(e),this},Player.prototype.removeAll=function(){for(var e=this._activePlayables.first;null!==e;){var a=e.next;e.object.stop(),e=a}return this._handlePlayablesToRemove(),this},Player.prototype.possess=function(e){return null===e._handle?!1:e._handle.container===this._activePlayables||e._handle.container===this._inactivePlayables},Player.prototype._handlePlayablesToRemove=function(){for(;this._playablesToRemove.length>0;){var e=this._playablesToRemove.pop(),a=e.object;a._handle=this._activePlayables.removeByReference(e)}0===this._activePlayables.length&&0===this._inactivePlayables.length&&this._onAllPlayablesRemoved()},Player.prototype.clear=function(){return this._activePlayables.clear(),this._inactivePlayables.clear(),this._playablesToRemove.clear(),this._controls.clear(),this},Player.prototype._warn=function(e){this._silent===!1&&console.warn(e),this._debug===!0},Player.prototype.silent=function(e){return this._silent=e||!1,this},Player.prototype.debug=function(e){return this._debug=e||!1,this},Player.prototype.stop=function(){for(var e=this._activePlayables.first;null!==e;){var a=e.next,t=e.object;t.stop(),e=a}this._handlePlayablesToRemove(),Playable.prototype.stop.call(this)},Player.prototype._activate=function(e){this._inactivePlayables.removeByReference(e._handle),e._handle=this._activePlayables.addBack(e)},Player.prototype._inactivate=function(e){return null===e._handle?void this._warn("[Playable.stop] Cannot stop a playable that is not running"):(this._activePlayables.removeByReference(e._handle),void(e._handle=this._inactivePlayables.addBack(e)))},Player.prototype._updatePlayableList=function(e){this._handlePlayablesToRemove();var a,t;e>0?(a=this._time-e,t=this._time):(a=this._time,t=this._time-e);for(var l=this._inactivePlayables.first;null!==l;){var i=l.object;l=l.next,i._overlaps(a,t)&&(this._activate(i),i._start())}},Player.prototype._update=function(e,a){this._updatePlayableList(e);for(var t=this._activePlayables.first;null!==t;t=t.next)void 0===a?t.object._moveTo(this._time,e):t.object._moveTo(this._time,e,a)},Player.prototype._onPlayableChanged=function(){},Player.prototype._onPlayableRemoved=function(){},Player.prototype._onAllPlayablesRemoved=function(){}; | ||
@@ -38,7 +38,7 @@ },{"./DoublyList":6,"./Playable":8}],10:[function(require,module,exports){ | ||
(function (global){ | ||
var root;"undefined"!=typeof window?root=window:"undefined"!=typeof global?root=global:(console.warn("[TINA] Your environment might not support TINA."),root=this);var requestAnimFrame=function(){return root.requestAnimationFrame||root.webkitRequestAnimationFrame||root.mozRequestAnimationFrame||root.oRequestAnimationFrame||root.msRequestAnimationFrame||function(t){root.setTimeout(t,1e3/60)}}(),clock=root.performance||Date,TINA={_tweeners:[],_defaultTweener:null,_startTime:0,_time:0,_running:!1,_onStart:null,_onPause:null,_onResume:null,_onUpdate:null,_onStop:null,_pauseOnLostFocus:!1,_pauseOnLostFocusInitialised:!1,onStart:function(t){return this._onStart=t,this},onUpdate:function(t){return this._onUpdate=t,this},onStop:function(t){return this._onStop=t,this},onPause:function(t){return this._onPause=t,this},isRunning:function(){return this._running===!0},update:function(){var t=clock.now()-this._startTime,e=t-this._time;0>e?(e=1,this._startTime-=1,this._time+=1):this._time=t;for(var n=this._tweeners.slice(0),i=0;i<n.length;i+=1)n[i]._moveTo(this._time,e);null!==this._onUpdate&&this._onUpdate(this._time,e)},reset:function(){var t=clock.now(),e=t-this._time;this._startTime+=e,this._time=0},start:function(){if(this._startAutomaticUpdate()!==!1){null!==this._onStart&&this._onStart();for(var t=0;t<this._tweeners.length;t+=1)this._tweeners[t]._start();return this}},stop:function(){if(this._stopAutomaticUpdate()!==!1){for(var t=this._tweeners.slice(0),e=0;e<t.length;e+=1)t[e].stop();return this._tweeners=t,null!==this._onStop&&this._onStop(),this}},_startAutomaticUpdate:function(){function t(){TINA._running===!0&&(TINA.update(),requestAnimFrame(t))}return this._running===!0?(console.warn("[TINA.start] TINA is already running"),!1):(this.reset(),this._running=!0,requestAnimFrame(t),!0)},_stopAutomaticUpdate:function(){return this._running===!1?(console.warn("[TINA.pause] TINA is not running"),!1):(this._running=!1,!0)},pause:function(){if(this._stopAutomaticUpdate()!==!1){for(var t=0;t<this._tweeners.length;t+=1)this._tweeners[t]._pause();return null!==this._onPause&&this._onPause(),this}},resume:function(){if(this._startAutomaticUpdate()!==!1){null!==this._onResume&&this._onResume();for(var t=0;t<this._tweeners.length;t+=1)this._tweeners[t]._resume();return this}},_initialisePauseOnLostFocus:function(){if(this._pauseOnLostFocusInitialised!==!0){if(void 0===document)return void console.warn("[TINA.pauseOnLostFocus] Cannot pause on lost focus because TINA is not running in a webpage (node.js does not allow this functionality)");var t,e;if("undefined"!=typeof document.hidden?(t="hidden",e="visibilitychange"):"undefined"!=typeof document.mozHidden?(t="mozHidden",e="mozvisibilitychange"):"undefined"!=typeof document.msHidden?(t="msHidden",e="msvisibilitychange"):"undefined"!=typeof document.webkitHidden&&(t="webkitHidden",e="webkitvisibilitychange"),"undefined"==typeof document[t])return void console.warn("[Tweener] Cannot pause on lost focus because the browser does not support the Page Visibility API");this._pauseOnLostFocusInitialised=!0;var n=!1;document.addEventListener(e,function(){document[t]&&(n=TINA.isRunning(),n&&TINA._pauseOnLostFocus&&TINA.pause()),document[t]||n&&TINA._pauseOnLostFocus&&TINA.resume()},!1)}},pauseOnLostFocus:function(t){return t===!0&&this._pauseOnLostFocusInitialised===!1&&this._initialisePauseOnLostFocus(),this._pauseOnLostFocus=t,this},setDefaultTweener:function(t){return this._defaultTweener=t,this._tweeners.push(this._defaultTweener),this},getDefaultTweener:function(){return this._defaultTweener},_add:function(t){this._running===!1&&this.start(),this._tweeners.push(t)},add:function(t){return this._tweeners.push(t),this},_inactivate:function(t){var e=this._tweeners.indexOf(t);-1!==e&&this._tweeners.splice(e,1)},remove:function(t){return this._inactivate(t),this},_getDefaultTweener:function(){if(null===this._defaultTweener){var t=this.Timer;this._defaultTweener=(new t).start()}return this._defaultTweener}};module.exports=root.TINA=TINA; | ||
var DoublyList=require("./DoublyList"),root;"undefined"!=typeof window?root=window:"undefined"!=typeof global?root=global:(console.warn("[TINA] Your environment might not support TINA."),root=this);var requestAnimFrame=function(){return root.requestAnimationFrame||root.webkitRequestAnimationFrame||root.mozRequestAnimationFrame||root.oRequestAnimationFrame||root.msRequestAnimationFrame||function(e){root.setTimeout(e,1e3/60)}}(),clock=root.performance||Date,TINA={_activeTweeners:new DoublyList,_inactiveTweeners:new DoublyList,_tweenersToRemove:new DoublyList,_defaultTweener:null,_startTime:0,_time:0,_running:!1,_onStart:null,_onPause:null,_onResume:null,_onUpdate:null,_onStop:null,_pauseOnLostFocus:!1,_pauseOnLostFocusInitialised:!1,onStart:function(e){return this._onStart=e,this},onUpdate:function(e){return this._onUpdate=e,this},onStop:function(e){return this._onStop=e,this},onPause:function(e){return this._onPause=e,this},isRunning:function(){return this._running===!0},update:function(){var e=clock.now()-this._startTime,t=e-this._time;for(0>t?(t=1,this._startTime-=1,this._time+=1):this._time=e;this._tweenersToRemove.length>0;){var n=this._tweenersToRemove.pop();n._handle=this._activeTweeners.removeByReference(n._handle)}for(;this._inactiveTweeners.length>0;){var i=this._inactiveTweeners.pop();i._handle=this._activeTweeners.addBack(i),i._start()}for(var s=this._activeTweeners.first;null!==s;s=s.next)s.object._moveTo(this._time,t);null!==this._onUpdate&&this._onUpdate(this._time,t)},reset:function(){var e=clock.now(),t=e-this._time;this._startTime+=t,this._time=0},start:function(){if(this._startAutomaticUpdate()!==!1){for(null!==this._onStart&&this._onStart();this._inactiveTweeners.length>0;){var e=this._inactiveTweeners.first;this._activate(e.object)}return this}},stop:function(){if(this._stopAutomaticUpdate()!==!1){for(;this._activePlayables.length>0;){var e=this._activePlayables.first;e.object.stop()}return null!==this._onStop&&this._onStop(),this}},_startAutomaticUpdate:function(){function e(){TINA._running===!0&&(TINA.update(),requestAnimFrame(e))}return this._running===!0?(console.warn("[TINA.start] TINA is already running"),!1):(this.reset(),this._running=!0,requestAnimFrame(e),!0)},_stopAutomaticUpdate:function(){return this._running===!1?(console.warn("[TINA.pause] TINA is not running"),!1):(this._running=!1,!0)},pause:function(){if(this._stopAutomaticUpdate()!==!1){for(var e=this._activeTweeners.first;null!==e;e=e.next)e.object._pause();return null!==this._onPause&&this._onPause(),this}},resume:function(){if(this._startAutomaticUpdate()!==!1){null!==this._onResume&&this._onResume();for(var e=this._activeTweeners.first;null!==e;e=e.next)e.object._resume();return this}},_initialisePauseOnLostFocus:function(){if(this._pauseOnLostFocusInitialised!==!0){if(void 0===document)return void console.warn("[TINA.pauseOnLostFocus] Cannot pause on lost focus because TINA is not running in a webpage (node.js does not allow this functionality)");var e,t;if("undefined"!=typeof document.hidden?(e="hidden",t="visibilitychange"):"undefined"!=typeof document.mozHidden?(e="mozHidden",t="mozvisibilitychange"):"undefined"!=typeof document.msHidden?(e="msHidden",t="msvisibilitychange"):"undefined"!=typeof document.webkitHidden&&(e="webkitHidden",t="webkitvisibilitychange"),"undefined"==typeof document[e])return void console.warn("[Tweener] Cannot pause on lost focus because the browser does not support the Page Visibility API");this._pauseOnLostFocusInitialised=!0;var n=!1;document.addEventListener(t,function(){document[e]&&(n=TINA.isRunning(),n&&TINA._pauseOnLostFocus&&TINA.pause()),document[e]||n&&TINA._pauseOnLostFocus&&TINA.resume()},!1)}},pauseOnLostFocus:function(e){return e===!0&&this._pauseOnLostFocusInitialised===!1&&this._initialisePauseOnLostFocus(),this._pauseOnLostFocus=e,this},_add:function(e){return this._running===!1&&this.start(),null===e._handle?(e._handle=this._inactiveTweeners.add(e),void(e._player=this)):e._handle.container===this._tweenersToRemove?void(e._handle=this._tweenersToRemove.removeByReference(e._handle)):void 0},add:function(e){return this._add(e),this},_inactivate:function(e){null!==e._handle&&this._activePlayables.removeByReference(e._handle),e._handle=this._inactivePlayables.addBack(e)},_remove:function(e){return null!==e._handle?e._handle.container===this._activeTweeners?void(e._handle=this._tweenersToRemove.add(e._handle)):e._handle.container===this._inactiveTweeners?void(e._handle=this._inactiveTweeners.removeByReference(e._handle)):void 0:void 0},remove:function(e){return this._remove(e),this},setDefaultTweener:function(e){return this._defaultTweener=e,this},getDefaultTweener:function(){if(null===this._defaultTweener){var e=this.Timer;this._defaultTweener=new e}return this._defaultTweener},_startDefaultTweener:function(){var e=this.getDefaultTweener();return this._add(e),e}};module.exports=root.TINA=TINA; | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}],13:[function(require,module,exports){ | ||
function Ticker(t){return this instanceof Ticker==!1?new Ticker(t):(Tweener.call(this),void(this.tupt=t||1))}var Tweener=require("./Tweener");Ticker.prototype=Object.create(Tweener.prototype),Ticker.prototype.constructor=Ticker,module.exports=Ticker,Ticker.prototype._moveTo=function(t,e){e=this.tupt,this._time=this.tupt*this._nbTicks++,this._update(e),null!==this._onUpdate&&this._onUpdate(this._time,e)},Ticker.prototype.convertToTicks=function(t){return t/this.tupt},Ticker.prototype.convertToTimeUnits=function(t){return t*this.tupt}; | ||
},{"./DoublyList":6}],13:[function(require,module,exports){ | ||
function Ticker(t){return this instanceof Ticker==!1?new Ticker(t):(Tweener.call(this),void(this.tupt=t||1))}var Tweener=require("./Tweener");Ticker.prototype=Object.create(Tweener.prototype),Ticker.prototype.constructor=Ticker,module.exports=Ticker,Ticker.prototype._moveTo=function(t,e){this._time+=this.tupt,e=this.tupt,this._update(e),null!==this._onUpdate&&this._onUpdate(this._time,e)},Ticker.prototype.convertToTicks=function(t){return t/this.tupt},Ticker.prototype.convertToTimeUnits=function(t){return t*this.tupt}; | ||
@@ -45,0 +45,0 @@ },{"./Tweener":19}],14:[function(require,module,exports){ |
@@ -43,11 +43,22 @@ var image = document.getElementById('image'); | ||
canvas.addEventListener('mousedown', function onTap(e) { | ||
e.preventDefault(); | ||
createAnimation(e.layerX, e.layerY); | ||
}, false); | ||
//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ | ||
for (var i = 0; i < 100; i++) { | ||
sprites.push(new Sprite(image)); | ||
} | ||
function triggerParticles() { | ||
var x = Math.random() * 400; | ||
var y = Math.random() * 400; | ||
createAnimation(x, y); | ||
TINA.Delay(500) | ||
.onComplete(triggerParticles) | ||
.start(); | ||
} | ||
triggerParticles(); | ||
// canvas.addEventListener('mousedown', function onTap(e) { | ||
// e.preventDefault(); | ||
// createAnimation(e.layerX, e.layerY); | ||
// }, false); |
@@ -22,7 +22,8 @@ var image = document.getElementById('image'); | ||
var motionDuration = 400; | ||
var sequence = new TINA.Sequence() | ||
.add( | ||
new TINA.Tween(sprites[0], ['x', 'y']) | ||
.from({ x: 100, y: 300 }) | ||
.to({ x: 100, y: 100 }, 500) | ||
new TINA.Tween(sprites[0], ['y']) | ||
.from({ y: 300 }) | ||
.to({ y: 100 }, motionDuration) | ||
.iterations(2) | ||
@@ -32,5 +33,5 @@ .pingpong(true) | ||
.add( | ||
new TINA.Tween(sprites[1], ['x', 'y']) | ||
.from({ x: 200, y: 300 }) | ||
.to({ x: 200, y: 100 }, 500) | ||
new TINA.Tween(sprites[1], ['y']) | ||
.from({ y: 300 }) | ||
.to({ y: 100 }, motionDuration) | ||
.iterations(2) | ||
@@ -40,5 +41,5 @@ .pingpong(true) | ||
.add( | ||
new TINA.Tween(sprites[2], ['x', 'y']) | ||
.from({ x: 300, y: 300 }) | ||
.to({ x: 300, y: 100 }, 500) | ||
new TINA.Tween(sprites[2], ['y']) | ||
.from({ y: 300 }) | ||
.to({ y: 100 }, motionDuration) | ||
.iterations(2) | ||
@@ -49,2 +50,3 @@ .pingpong(true) | ||
.iterations(Infinity) | ||
.start(); | ||
.start(); | ||
{ | ||
"name": "tina", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"description": "Tweening and INterpolations for Animation", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -14,3 +14,3 @@ # TINA | ||
* **High customizability** (possibility to use custom easings, interpolations and components) | ||
* **Running options** (delay, iterations, pingpong, persist and speed) | ||
* **Play options** (delay, iterations, pingpong, persist and speed) | ||
* **Open source** and MIT License (use it as you please) | ||
@@ -20,3 +20,3 @@ * A consequent library of **easing and interpolation methods** | ||
* **Good synchronisation** between tweens | ||
* **Relative tweening** enables the possibility to alter objects while they are tweening | ||
* **Relative tweening** enables the possibility to apply several simultaneous tweens on a single property | ||
* **Nested object tweening** enables the possibility to alter nested objects using a single tween | ||
@@ -23,0 +23,0 @@ * **Compatible with Node.js!** |
@@ -11,4 +11,4 @@ | ||
this._iterations = 1; // Number of times to iterate the playable | ||
this._pingpong = false; // To make the playable go backward on even iterations | ||
this._persist = false; // To keep the playable running instead of completing | ||
this._pingpong = false; // To make the playable go backward on even iterations | ||
this._persist = false; // To keep the playable running instead of completing | ||
} | ||
@@ -170,4 +170,4 @@ | ||
BriefExtension.prototype._moveTo = function (time, dt, overflow) { | ||
var epsilon = 1e-6; | ||
BriefExtension.prototype._moveTo = function (time, dt, playerOverflow) { | ||
dt *= this._speed; | ||
@@ -177,62 +177,54 @@ | ||
// That is why this extension exists | ||
if (overflow === undefined) { | ||
// Computing overflow and clamping time | ||
if (dt !== 0) { | ||
if (this._iterations === 1) { | ||
// Converting into local time (relative to speed and starting time) | ||
this._time = (time - this._startTime) * this._speed; | ||
if (dt > 0) { | ||
if (this._time >= this._duration) { | ||
overflow = this._time - this._duration; | ||
dt -= overflow; | ||
this._time = this._duration; | ||
} | ||
} else if (dt < 0) { | ||
if (this._time <= 0) { | ||
overflow = this._time; | ||
dt -= overflow; | ||
this._time = 0; | ||
} | ||
// i.e playables without durations do not need all those options | ||
// Computing overflow and clamping time | ||
var overflow; | ||
if (dt !== 0) { | ||
if (this._iterations === 1) { | ||
// Converting into local time (relative to speed and starting time) | ||
this._time = (time - this._startTime) * this._speed; | ||
if (dt > 0) { | ||
if (this._time >= this._duration) { | ||
overflow = this._time - this._duration; | ||
// dt -= overflow; | ||
this._time = this._duration; | ||
} else if (this._time < 0) { | ||
} | ||
} else { | ||
time = (time - this._startTime) * this._speed; | ||
} else if (dt < 0) { | ||
if (this._time <= 0) { | ||
overflow = this._time; | ||
// dt -= overflow; | ||
this._time = 0; | ||
} | ||
} | ||
} else { | ||
time = (time - this._startTime) * this._speed; | ||
// Iteration at current update | ||
var iteration = time / this._duration; | ||
// Iteration at current update | ||
var iteration = time / this._duration; | ||
if (dt > 0) { | ||
if (0 < iteration && iteration < this._iterations) { | ||
this._time = time % this._duration; | ||
} else { | ||
overflow = (iteration - this._iterations) * this._duration; | ||
this._time = this._duration * (1 - (Math.ceil(this._iterations) - this._iterations)); | ||
} | ||
} else if (dt < 0) { | ||
if (0 < iteration && iteration < this._iterations) { | ||
this._time = time % this._duration; | ||
} else { | ||
overflow = iteration * this._duration; | ||
this._time = 0; | ||
} | ||
} | ||
if (dt > 0) { | ||
if (iteration < this._iterations) { | ||
// if (this._time !== 0 && Math.ceil(iteration) !== Math.ceil(this._time / this._duration)) { | ||
// } | ||
this._time = time % this._duration; | ||
} else { | ||
overflow = (iteration - this._iterations) * this._duration; | ||
dt -= overflow; | ||
this._time = this._duration * (1 - (Math.ceil(this._iterations) - this._iterations)); | ||
if ((this._pingpong === true)) { | ||
if (overflow === undefined) { | ||
if ((Math.ceil(iteration) & 1) === 0) { | ||
this._time = this._duration - this._time; | ||
} | ||
} else if (dt < 0) { | ||
if (0 < iteration) { | ||
// if (this._time !== this._duration && Math.ceil(iteration) !== Math.ceil(this._time / this._duration)) { | ||
// } | ||
this._time = time % this._duration; | ||
} else { | ||
overflow = iteration * this._duration; | ||
dt -= overflow; | ||
this._time = 0; | ||
} | ||
} | ||
if ((this._pingpong === true)) { | ||
} else { | ||
if (Math.ceil(this._iterations) === this._iterations) { | ||
if (overflow === undefined) { | ||
if ((Math.ceil(iteration) & 1) === 0) { | ||
this._time = this._duration - this._time; | ||
} | ||
} else { | ||
if ((Math.ceil(iteration) & 1) === 1) { | ||
this._time = this._duration - this._time; | ||
} | ||
} | ||
} else { | ||
if ((Math.ceil(iteration) & 1) === 0) { | ||
if ((Math.ceil(this._iterations) & 1) === 0) { | ||
this._time = this._duration - this._time; | ||
@@ -244,3 +236,5 @@ } | ||
} | ||
} else { | ||
} | ||
if (playerOverflow !== undefined && overflow === undefined) { | ||
// Ensuring that the playable overflows when its player overflows | ||
@@ -250,11 +244,11 @@ // This conditional is to deal with Murphy's law: | ||
// does not complete due to stupid rounding errors | ||
if (dt > 0) { | ||
overflow = Math.max((time - this._startTime) * this._speed - this._duration * this.iterations, 0); | ||
if (dt > 0 && this.duration - this._time < epsilon) { | ||
// overflow = Math.max((time - this._startTime) * this._speed - this._duration * this._iterations, overflow); | ||
overflow = playerOverflow; | ||
this._time = this._duration; | ||
} else { | ||
overflow = Math.min((time - this._startTime) * this._speed, 0); | ||
} else if (dt < 0 && this._time < epsilon) { | ||
// overflow = Math.min((time - this._startTime) * this._speed, overflow); | ||
overflow = playerOverflow; | ||
this._time = 0; | ||
} | ||
dt -= overflow; | ||
} | ||
@@ -265,3 +259,7 @@ | ||
if (this._onUpdate !== null) { | ||
this._onUpdate(this._time, dt); | ||
if (overflow === undefined) { | ||
this._onUpdate(this._time, dt); | ||
} else { | ||
this._onUpdate(this._time, dt - overflow); | ||
} | ||
} | ||
@@ -268,0 +266,0 @@ |
@@ -153,3 +153,3 @@ /** @class */ | ||
if (this._player === null) { | ||
this._player = TINA._getDefaultTweener(); | ||
this._player = TINA._startDefaultTweener(); | ||
} | ||
@@ -183,3 +183,3 @@ | ||
if (this._player === null) { | ||
console.warn('[Playable.stop] Cannot stop a playable that is not running'); | ||
console.warn('[Playable.stop] Trying to stop a playable that was never started.'); | ||
return; | ||
@@ -189,3 +189,3 @@ } | ||
// Stopping playable without performing any additional update nor completing | ||
if (this._player._inactivate(this) === false) { | ||
if (this._player._remove(this) === false) { | ||
// Could not be removed | ||
@@ -214,3 +214,3 @@ return this; | ||
Playable.prototype.pause = function () { | ||
if (this._player._inactivate(this) === false) { | ||
if (this._player._remove(this) === false) { | ||
// Could not be paused | ||
@@ -217,0 +217,0 @@ return this; |
@@ -1,3 +0,3 @@ | ||
var Playable = require('./Playable'); | ||
var DoublyList = require('./DoublyList'); | ||
var Playable = require('./Playable'); | ||
var DoublyList = require('./DoublyList'); | ||
@@ -29,3 +29,3 @@ /** | ||
// Whether to silence warnings | ||
this._silent = false; | ||
this._silent = true; | ||
@@ -138,3 +138,2 @@ // Whether to trigger the debugger on warnings | ||
playable._handle = this._activePlayables.removeByReference(handle); | ||
playable._player = null; | ||
} | ||
@@ -167,3 +166,3 @@ | ||
Player.prototype.silent = function (silent) { | ||
this._silent = silent; | ||
this._silent = silent || false; | ||
return this; | ||
@@ -173,3 +172,3 @@ }; | ||
Player.prototype.debug = function (debug) { | ||
this._debug = debug; | ||
this._debug = debug || false; | ||
return this; | ||
@@ -179,7 +178,2 @@ }; | ||
Player.prototype.stop = function () { | ||
if (this._player === null) { | ||
this._warn('[Player.stop] Cannot stop a player that is not running'); | ||
return; | ||
} | ||
// Stopping all active playables | ||
@@ -195,3 +189,2 @@ var handle = this._activePlayables.first; | ||
this._handlePlayablesToRemove(); | ||
Playable.prototype.stop.call(this); | ||
@@ -207,2 +200,7 @@ }; | ||
Player.prototype._inactivate = function (playable) { | ||
if (playable._handle === null) { | ||
this._warn('[Playable.stop] Cannot stop a playable that is not running'); | ||
return; | ||
} | ||
// O(1) | ||
@@ -234,3 +232,3 @@ this._activePlayables.removeByReference(playable._handle); | ||
// Starting if player time within playable bounds | ||
// if (playable._isTimeWithin(this._time)) { | ||
// console.log('Should playable be playing?', playable._startTime, time0, time1, dt) | ||
if (playable._overlaps(time0, time1)) { | ||
@@ -246,3 +244,7 @@ this._activate(playable); | ||
for (var handle = this._activePlayables.first; handle !== null; handle = handle.next) { | ||
handle.object._moveTo(this._time, dt, overflow); | ||
if (overflow === undefined) { | ||
handle.object._moveTo(this._time, dt); | ||
} else { | ||
handle.object._moveTo(this._time, dt, overflow); | ||
} | ||
} | ||
@@ -249,0 +251,0 @@ }; |
@@ -20,3 +20,2 @@ var Tweener = require('./Tweener'); | ||
this.tupt = tupt || 1; | ||
this._nbTicks = 0; | ||
@@ -29,4 +28,6 @@ } | ||
Ticker.prototype._moveTo = function (time, dt) { | ||
this._time += this.tupt; | ||
// overwriting elapsed time since previous iteration | ||
dt = this.tupt; | ||
this._time = this.tupt * (this._nbTicks++); | ||
@@ -33,0 +34,0 @@ this._update(dt); |
@@ -40,2 +40,2 @@ var BriefPlayer = require('./BriefPlayer'); | ||
return this; | ||
}; | ||
}; |
141
src/TINA.js
var DoublyList = require('./DoublyList'); | ||
/** | ||
@@ -27,3 +29,3 @@ * | ||
// Method to trigger automatic update of TINA | ||
// Method to trigger automatic updates | ||
var requestAnimFrame = (function(){ | ||
@@ -44,4 +46,13 @@ return root.requestAnimationFrame || | ||
var TINA = { | ||
_tweeners: [], | ||
// List of active tweeners handled by TINA | ||
_activeTweeners: new DoublyList(), | ||
// List of inactive tweeners handled by TINA | ||
_inactiveTweeners: new DoublyList(), | ||
// List of tweeners that are not handled by this player anymore and are waiting to be removed | ||
_tweenersToRemove: new DoublyList(), | ||
// _tweeners: [], | ||
_defaultTweener: null, | ||
@@ -105,11 +116,25 @@ | ||
// Making a copy of the tweener array | ||
// to avoid funky stuff happening | ||
// due to addition or removal of tweeners | ||
// while iterating them | ||
var runningTweeners = this._tweeners.slice(0); | ||
for (var t = 0; t < runningTweeners.length; t += 1) { | ||
runningTweeners[t]._moveTo(this._time, dt); | ||
// Removing any tweener that is requested to be removed | ||
while (this._tweenersToRemove.length > 0) { | ||
// Removing from list of tweeners to remove | ||
var tweenerToRemove = this._tweenersToRemove.pop(); | ||
// Removing from list of active tweeners | ||
tweenerToRemove._handle = this._activeTweeners.removeByReference(tweenerToRemove._handle); | ||
} | ||
// Activating any inactive tweener | ||
while (this._inactiveTweeners.length > 0) { | ||
// Removing from list of inactive tweeners | ||
var tweenerToActivate = this._inactiveTweeners.pop(); | ||
// Adding to list of active tweeners | ||
tweenerToActivate._handle = this._activeTweeners.addBack(tweenerToActivate); | ||
tweenerToActivate._start(); | ||
} | ||
for (var handle = this._activeTweeners.first; handle !== null; handle = handle.next) { | ||
handle.object._moveTo(this._time, dt); | ||
} | ||
if (this._onUpdate !== null) { | ||
@@ -141,4 +166,5 @@ this._onUpdate(this._time, dt); | ||
for (var t = 0; t < this._tweeners.length; t += 1) { | ||
this._tweeners[t]._start(); | ||
while (this._inactiveTweeners.length > 0) { | ||
var handle = this._inactiveTweeners.first; | ||
this._activate(handle.object); | ||
} | ||
@@ -154,11 +180,7 @@ | ||
var runningTweeners = this._tweeners.slice(0); | ||
for (var t = 0; t < runningTweeners.length; t += 1) { | ||
runningTweeners[t].stop(); | ||
while (this._activePlayables.length > 0) { | ||
var handle = this._activePlayables.first; | ||
handle.object.stop(); | ||
} | ||
// Stopping the tweeners have the effect of automatically removing them from TINA | ||
// In this case we want to keep them attached to TINA | ||
this._tweeners = runningTweeners; | ||
if (this._onStop !== null) { | ||
@@ -171,3 +193,3 @@ this._onStop(); | ||
// internal start method, called by start and resume | ||
// Internal start method, called by start and resume | ||
_startAutomaticUpdate: function () { | ||
@@ -211,4 +233,4 @@ if (this._running === true) { | ||
for (var t = 0; t < this._tweeners.length; t += 1) { | ||
this._tweeners[t]._pause(); | ||
for (var handle = this._activeTweeners.first; handle !== null; handle = handle.next) { | ||
handle.object._pause(); | ||
} | ||
@@ -231,4 +253,4 @@ | ||
for (var t = 0; t < this._tweeners.length; t += 1) { | ||
this._tweeners[t]._resume(); | ||
for (var handle = this._activeTweeners.first; handle !== null; handle = handle.next) { | ||
handle.object._resume(); | ||
} | ||
@@ -304,12 +326,2 @@ | ||
setDefaultTweener: function (tweener) { | ||
this._defaultTweener = tweener; | ||
this._tweeners.push(this._defaultTweener); | ||
return this; | ||
}, | ||
getDefaultTweener: function () { | ||
return this._defaultTweener; | ||
}, | ||
_add: function (tweener) { | ||
@@ -322,7 +334,19 @@ // A tweener is starting | ||
this._tweeners.push(tweener); | ||
if (tweener._handle === null) { | ||
// Tweener can be added | ||
tweener._handle = this._inactiveTweeners.add(tweener); | ||
tweener._player = this; | ||
return; | ||
} | ||
// Tweener is already handled | ||
if (tweener._handle.container === this._tweenersToRemove) { | ||
// Playable was being removed, removing from playables to remove | ||
tweener._handle = this._tweenersToRemove.removeByReference(tweener._handle); | ||
return; | ||
} | ||
}, | ||
add: function (tweener) { | ||
this._tweeners.push(tweener); | ||
this._add(tweener); | ||
return this; | ||
@@ -332,22 +356,53 @@ }, | ||
_inactivate: function (tweener) { | ||
var tweenerIdx = this._tweeners.indexOf(tweener); | ||
if (tweenerIdx !== -1) { | ||
this._tweeners.splice(tweenerIdx, 1); | ||
if (tweener._handle !== null) { | ||
this._activePlayables.removeByReference(tweener._handle); | ||
} | ||
tweener._handle = this._inactivePlayables.addBack(tweener); | ||
}, | ||
_remove: function (tweener) { | ||
if (tweener._handle === null) { | ||
return; | ||
} | ||
// Playable is handled, either by this player or by another one | ||
if (tweener._handle.container === this._activeTweeners) { | ||
// Tweener was active, adding to remove list | ||
tweener._handle = this._tweenersToRemove.add(tweener._handle); | ||
return; | ||
} | ||
if (tweener._handle.container === this._inactiveTweeners) { | ||
// Tweener was inactive, removing from inactive tweeners | ||
tweener._handle = this._inactiveTweeners.removeByReference(tweener._handle); | ||
return; | ||
} | ||
}, | ||
remove: function (tweener) { | ||
this._inactivate(tweener); | ||
this._remove(tweener); | ||
return this; | ||
}, | ||
_getDefaultTweener: function () { | ||
setDefaultTweener: function (tweener) { | ||
this._defaultTweener = tweener; | ||
return this; | ||
}, | ||
getDefaultTweener: function () { | ||
if (this._defaultTweener === null) { | ||
// If a default tweener is required but non exist | ||
// Then it is started in addition to being created | ||
// If a default tweener is required but none exist | ||
// Then we create one | ||
var DefaultTweener = this.Timer; | ||
this._defaultTweener = new DefaultTweener().start(); | ||
this._defaultTweener = new DefaultTweener(); | ||
} | ||
return this._defaultTweener; | ||
}, | ||
_startDefaultTweener: function () { | ||
var defaultTweener = this.getDefaultTweener(); | ||
this._add(defaultTweener); | ||
return defaultTweener; | ||
} | ||
@@ -354,0 +409,0 @@ }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
770720
8391