Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
dalisoft edited this page Aug 4, 2017 · 2 revisions

Event / Emit Event

There are 3 type of event listener method and 1 call event method.

import TWEEN, { Tween, Easing, Interpolation } from 'es6-tween';
const t = new Tween({ x : 0 }).to({ x : 100 }, 2000).start();

// Event "on" example
t.on('update', ({ x }) => {
console.log(`The current x value is ${x}`);
});

// Event "once" example
t.once('update', ({ x }) => {
console.log('The update callback was called once');
});

// Event "off" example
t.off('update'); // `on('update', ...)` was deleted and not anymore was call

// Custom event and emit calling
t.on('xReach50', ({ x }) => {
console.log('Hooray! ', 'The { x } was calling from half-start');
});

t.on('update', ({ x }) => {
if (x >= 50) {
t.emit('xReach50', { x - 50 });
}
});
Clone this wiki locally