parseq-tasks
v1.0.6
Published
The tasks' update dt (delta time) is managed in seconds.
Downloads
4
Readme
###Manage nested tasks in Parallel or in Sequence.
The tasks' update dt (delta time) is managed in seconds.
const TICK = 1 / 60;
const TASK = new Parallel();
const POINT = {x: 0, y: 0};
setInterval(() => {
TASK.update(TICK);
}, TICK * 1000);
TASK.add(new Sequence(
new Excecute(() => { console.log("1") }),
new Wait(1),
new Excecute(() => { console.log("2") }),
new Wait(1),
new Parallel(
new Excecute(() => { console.log("3") }),
new Excecute(() => { console.log("4") }),
new Ease(2, POINT, {x: 2}),
new Ease(2, POINT, {y: 3}),
),
new Excecute(() => { console.log(POINT) }),
new Wait(1),
new Excecute(() => { console.log("5") }),
));
Extend from the Task class to develop your custom tasks.
export class ImageLoader extends Task {
constructor(url) {
super();
this.start = false;
this.url = url;
this.image = null;
}
update(dt) {
if (this.start === false) {
this.start = true;
this.image = new Image();
this.image.src = this.url;
this.image.onload = () => {
this.done = true;
};
}
}
}