TINA
Tweening and INterpolations for Animation
A comprehensive, high performance, easy to use, open source animation library in JavaScript.
- Easy to use (API strongly inspired by Tween.js)
- High performance (Competitive with Tweenjs and GSAP, benchmark coming soon)
- High flexibility (tween transitions can easily be modified after creation)
- High customizability (possibility to use custom easings, interpolations and components)
- Play options (delay, iterations, pingpong, persist and speed)
- Open source and MIT License (use it as you please)
- A consequent library of easing and interpolation methods
- A variety of components such as Timeline, Sequence and Recorder (CSSTween coming soon)
- Good synchronisation between tweens
- 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
- Compatible with Node.js!
- Bonus: Creation and removal of tweens within the callback of another tween will not result in any unwanted side effect (infamous bug of other tweening libraries)
Note: Do not hesitate to contribute by reporting issues or by submitting your own components and interpolations.
Warning: Still in beta version! Do not be shy, report issues
How to use
In a browser
Include TINA's build in your html using either the minified library or the unminified version.
In Node.js
Install TINA using npm install tina
, then require it:
var TINA = ;
JSFiddle examples
API
Existing playable components are: Tween, NestedTween, Timeline, Sequence, Delay, Timer, Ticker, Recorder (CSSTween coming soon). The following is a non-exhaustive list of possibilities offered by TINA.
Tween
To create and start a tween (it will be automatically updated):
var myObject = x: 0 ;var properties = 'x';var duration = 500; // in millisecondsvar myTween = myObject propertiesstart;
To create and start a tween without affecting it to a variable:
TINAstart;
To tween an array:
var myArray = 0 1 0;var myTween = myArraystart;
To tween several properties:
var myTween = myObject 'x' 'y'start;
To chain several transitions:
var myTween = myObject 'x'start;
To ease the tweening:
var myObject = x: 0 ;var easingParameter = 2;var myTween = myObject 'x'start;// orvar myTween = myObject 'x'start;
To use interpolation functions:
var myObject = abc: 'Hello' ;var myTween = myObject 'abc'start;// orvar myTween = myObject 'abc'start;
To start tweening after a given delay:
var myTween = myObject 'x';
To add callbacks on specific events:
var myTween = myObject 'x';
NestedTween
Nested tweens give the ability to tween nested objects using a single tween. A nested tween allows to interpolate between nested objects. To tween a nested tween:
var nestedObject =position: x: 0 y: 0alpha: 0var myNestedTween = nestedObject 'position.x' 'position.y' 'alpha'start;
Note: the NestedTween API remains identical to Tween and all the functionalities of Tween are available to the NestedTween component.
Timeline
Timelines are used to play tweens in parallel. To create a timeline:
var timePosTweenA = 0;var timePosTweenB = 2000;var myTimeline =start;
Sequence
Sequences are used to chain tweens. To create a sequence:
// 1 second delay between the end of myTweenB and the start of myTweenCvar mySequence =start;
Delay
To create a delay:
var myDelay = duration;
Delays can be used as a setTimeout
that would be synchronised with all the other tweens.
It can also be used to apply some treatment to objects for a given duration.
For example, moving a particle for a fixed duration and then destroy it:
var particleSpeedX = 5;var particleSpeedY = 0;var myParticle = ;start;
Tweener
A tweener is responsible for tweening playable components. The tweener can be either a timer or a ticker.
If no tweener is specified, any started playable will be tweened by the default tweener.
// myTween will be tweened by the default tweenervar myTween = myObject 'x'start;
To manually specify a tweener for a playable component:
// myTween will be tweened by myTweenervar myTween = myObject 'x'start;
To specify the default tweener for every tween:
// I choose a timer as my default tweenervar myTimer = ;// myTween will be attached to myTimervar myTween = myObject 'x'start;
Timer
At every update its internal time is increased by a fixed proportion of the time elapsed since the previous update. To create a default timer that will update automatically:
var myTimer = start;
To create a timer and update it manually:
var myTimer = ;TINA;{TINA;;};
It is possible to specify the speed at which time will elapse for the timer.
This flexbility allows the user to use units that he is comfortable with.
It could be 1 unit per second
, 24 ups
, 60 ups
or 1000 ups
(or even 237.6 ups
if you come from another planet).
By default the timer goes at a speed of 1000 units per second (milliseconds).
Every second, the time will increase by the given tups
:
var tups = 60; // Time units per secondvar myTimer = tups;
Effect of different values for the tups
:
var myTimer1 = 1;var myTimer60 = 60;var myTimer1000 = 1000;// The following will tween myObject in 100 secondsTINA;// The following will tween myObject in 1.667 secondsTINA;// The following will tween myObject in 0.1 secondsTINA;
Ticker
At every update its internal time is increased by a fixed amount.
To create a ticker with automatic updates:
var myTicker = start;
To create a ticker and update it manually:
var myTicker = ;TINA;{TINA;;};
By default the ticker goes at a speed of 1 unit per update.
But similarly to a timer it is possible to specify how fast the time goes for a ticker.
At every update the time will increase by the given tupt
:
var tupt = 2; // Time units per tick/updatevar myTicker = tupt;
Effect of different values for the tupt
:
var myTicker1 = 1;var myTicker10 = 10;var myTicker20 = 20;// The following will tween myObject in 100 updatesTINA;// The following will tween myObject in 10 updatesTINA;// The following will tween myObject in 5 updatesTINA;
TINA's update callback
In the case when tweeners automatically update, TINA can be used as the main loop of the application.
// t is the total time elapsed since TINA started// dt is the time elapsed since TINA's previous update// both durations are in millisecondsTINA;
Made in Wizcorp.