diff --git a/examples/00_hello_world.html b/examples/00_hello_world.html index b7c2585..51dd1fd 100644 --- a/examples/00_hello_world.html +++ b/examples/00_hello_world.html @@ -16,13 +16,14 @@ + diff --git a/examples/01_bars.html b/examples/01_bars.html index 22d104e..6e5ad71 100644 --- a/examples/01_bars.html +++ b/examples/01_bars.html @@ -14,13 +14,14 @@
+ diff --git a/examples/02_black_and_red.html b/examples/02_black_and_red.html index 24b6391..da72b00 100644 --- a/examples/02_black_and_red.html +++ b/examples/02_black_and_red.html @@ -22,12 +22,13 @@ + diff --git a/examples/03_graphs.html b/examples/03_graphs.html index 0f01a0e..6444502 100644 --- a/examples/03_graphs.html +++ b/examples/03_graphs.html @@ -26,119 +26,129 @@
+ diff --git a/examples/04_simplest.html b/examples/04_simplest.html index dcf047c..dd21f6b 100644 --- a/examples/04_simplest.html +++ b/examples/04_simplest.html @@ -16,27 +16,39 @@ + diff --git a/examples/05_spline.html b/examples/05_spline.html deleted file mode 100644 index df473f2..0000000 --- a/examples/05_spline.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - Tween.js / Spline - - - - - -
-

tween.js

-

05 _ Spline

-

Catmull-Rom. It's all you need.

-
- -
- - - - - diff --git a/examples/05_video_and_time.html b/examples/05_video_and_time.html new file mode 100644 index 0000000..30afad2 --- /dev/null +++ b/examples/05_video_and_time.html @@ -0,0 +1,67 @@ + + + + Tween.js / video and time + + + + +
+

tween.js

+

05 _ video and time

+

Playing a video, synchronizing a tween to it

+
+ +
+ +
+ + + + + + diff --git a/examples/06_array_interpolation.html b/examples/06_array_interpolation.html new file mode 100644 index 0000000..c5085df --- /dev/null +++ b/examples/06_array_interpolation.html @@ -0,0 +1,144 @@ + + + + Tween.js / array interpolation + + + + + +
+

tween.js

+

06 _ array interpolation

+

The different interpolations if arrays are used as values.

+
+ +
+ + + + + + diff --git a/examples/06_video_and_time.html b/examples/06_video_and_time.html deleted file mode 100644 index a37ec2f..0000000 --- a/examples/06_video_and_time.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - Tween.js / video and time - - - - -
-

tween.js

-

06 _ video and time

-

Playing a video, synchronizing a tween to it

-
- -
- -
- - - - - diff --git a/examples/07_autostart.html b/examples/07_autostart.html deleted file mode 100644 index 4af6757..0000000 --- a/examples/07_autostart.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - Tween.js / autostart - - - - -
-

tween.js

-

07 _ autostart

-

With autostart, TWEEN is started and stopped automatically.

- - - -
- -
-
- - - - - - diff --git a/examples/08_array_interpolation.html b/examples/08_array_interpolation.html deleted file mode 100644 index 52e67cf..0000000 --- a/examples/08_array_interpolation.html +++ /dev/null @@ -1,131 +0,0 @@ - - - - Tween.js / array interpolation - - - - - -
-

tween.js

-

08 _ array interpolation

-

The different interpolations if arrays are used as values.

-
- -
- - - - - diff --git a/examples/js/RequestAnimationFrame.js b/examples/js/RequestAnimationFrame.js new file mode 100644 index 0000000..0e1ee69 --- /dev/null +++ b/examples/js/RequestAnimationFrame.js @@ -0,0 +1,30 @@ +// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ +// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating + +// requestAnimationFrame polyfill by Erik Möller +// fixes from Paul Irish and Tino Zijdel + +(function() { + var lastTime = 0; + var vendors = ['ms', 'moz', 'webkit', 'o']; + for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; + window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] + || window[vendors[x]+'CancelRequestAnimationFrame']; + } + + if (!window.requestAnimationFrame) + window.requestAnimationFrame = function(callback, element) { + var currTime = new Date().getTime(); + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); + var id = window.setTimeout(function() { callback(currTime + timeToCall); }, + timeToCall); + lastTime = currTime + timeToCall; + return id; + }; + + if (!window.cancelAnimationFrame) + window.cancelAnimationFrame = function(id) { + clearTimeout(id); + }; +}()); diff --git a/src/Tween.js b/src/Tween.js index c81395d..5631fe1 100644 --- a/src/Tween.js +++ b/src/Tween.js @@ -12,62 +12,14 @@ var TWEEN = TWEEN || ( function () { - var _interval = null, _fps = 60, _autostart = false, _tweens = []; + var _tweens = []; return { - setFPS: function ( fps ) { - - _fps = fps || 60; - - }, - - start: function ( fps ) { - - if ( fps ) { - - this.setFPS( fps ); - - } - - if ( _interval === null ) { - - _interval = setInterval( this.update, 1000 / _fps ); - - } - - }, - - stop: function () { - - clearInterval( _interval ); - - _interval = null; - - }, - - setAutostart: function ( value ) { - - _autostart = value; - - if ( _autostart && _tweens.length ) { - - this.start(); - - } - - }, - add: function ( tween ) { _tweens.push( tween ); - if ( _autostart ) { - - this.start(); - - } - }, getAll: function () { @@ -113,12 +65,6 @@ var TWEEN = TWEEN || ( function () { } - if ( num_tweens === 0 && _autostart ) { - - TWEEN.stop(); - - } - } }; @@ -171,7 +117,8 @@ TWEEN.Tween = function ( object ) { TWEEN.add( this ); - _startTime = time ? time + _delayTime : Date.now() + _delayTime; + _startTime = time || Date.now(); + _startTime += _delayTime; for ( var property in _valuesEnd ) { @@ -313,13 +260,6 @@ TWEEN.Tween = function ( object ) { }; - /* - this.destroy = function () { - - TWEEN.remove( this ); - - }; - */ }; TWEEN.Easing = { Linear: {}, Quadratic: {}, Cubic: {}, Quartic: {}, Quintic: {}, Sinusoidal: {}, Exponential: {}, Circular: {}, Elastic: {}, Back: {}, Bounce: {} };