Wheen
A lite-weight animation solution.
Integrated with Cocos Creator.
Even possible to tween nested attributes!
Usage
Simple
const obj = {x: 0, y: 0};
wheen(obj)
.to({x: 10, y: 20}, 1000)
.start();
Delay
const obj = {x: 0, y: 0};
wheen(obj)
.wait(1000)
.to({x: 10, y: 20}, 1000)
.start();
From Attributes
const obj = {x: 0, y: 0};
wheen(obj)
.from({x: -10})
.to({x: 10, y: 20}, 1000)
.start();
Call Function
const obj = {x: 0, y: 0};
wheen(obj)
.to({x: 10, y: 20}, 1000)
.callFunc(()=>{ console.log('Finished!') })
.start();
Loop
const obj = {x: 0, y: 0};
wheen(obj)
.to({x: 10, y: 20}, 1000)
.to({x: 0, y: 0}, 1000)
.loop(3)
.start();
Easing
const obj = {x: 0, y: 0};
wheen(obj)
.to({x: 10, y: 20}, 1000, Wheen.Easing.Cubic.easeOut)
.start();
Nested Attributes
const obj = {
x: 0,
y: 0,
child: {x: 0, y: 0}
};
wheen(obj)
.to({
x: 10,
child: {
x: 20
}
}, 1000)
.start();
Differentiate Assignment
const obj = {x: 0, y: 0};
wheen(obj)
.to(
{x: 10, y: 20},
1000
{x: Wheen.Easing.Back.easeOut, y: Wheen.Easing.Linear}
)
.start();
Pre-assign methods
const box = document.getElementById('box');
wheen(obj)
.to(
{ marginLeft: 200 }
1000
Wheen.Easing.Linear,
{
get: value => value.replace('px', ''),
set: value => value + 'px'
}
)
.start();
Events
const obj = {x: 0, y: 0};
wheen(obj)
.to({x: 10}, 1000, Wheen.Easing.Linear)
.on('start', ()=> console.log('Tween start'));
.on('update', () => console.log('Tween update'));
.on('finish', ()=> console.log('Tween end'));
.start();
Full Usage
const obj = {x: 0, y: 0, scaleX: 1, scaleY: 1};
let w = wheen(obj)
.from({x: 0, y: 0, scaleX: 1, scaleY: 1})
.to({x: 50}, 1000)
.setFlag('START')
.to({scaleX: 1.2, scaleY: 0.8}, 50, Wheen.Easing.Cubic.easeIn)
.to({scaleX: 0.8, scaleY: 1.2}, 50, Wheen.Easing.Cubic.easeOut)
.to({y: 500}, 1000, Wheen.Easing.Cubic.easeOut)
.callFunc(()=>{console.log("I'm on the air!")})
.to({y: 0}, 1000, Wheen.Easing.Cubic.easeIn)
.to({scaleX: 1.2, scaleY: 0.8}, 50, Wheen.Easing.Cubic.easeIn)
.to({scaleX: 1, scaleY: 1}, 50, Wheen.Easing.Cubic.easeOut)
.loop(2, 'START')
.on('finish', function(){ console.log(`Finished at ${this.x}!`); }, obj)
w.start();
w.pause();
Wheen.resume(obj);
Wheen.stop(obj);