Answer the question
In order to leave comments, you need to log in
How to animate on fabric.js?
Hello everyone, I'm trying to learn canvas animation on fabricjs . Everything works, but I can't get good fps in any way. Tell me, please, what am I doing wrong?
First, we create a fabric.canvas object, after which we create a 16x16 array, which I fill with fabric.rect objects:
var canvas = new fabric.Canvas('canvas', { selection: false });
var objects = new Array();
for (var x = 1; x <= 16; x++) {
objects[x] = new Array();
for (var y = 1; y <= 16; y++) {
var rect = new fabric.Rect({
left: (350/8)*(x-1)+40,
top: (350/8)*(y-1-8),
fill: 'red',
width: 34,
height: 34
});
objects[x][y] = {
type: 'square',
object: rect
}
canvas.add(rect);
}
}
var startTime = Date.now();
(function animate() {
var current = Date.now() - startTime;
for (var x = 1; x <= 16; x++) {
for (var y = 1; y <= 16; y++) {
objects[x][y].object.top = fabric.util.ease.easeOutBounce(current, (350/8/5)*(y-1-8), (350/8)*(y-1)+40+((350/8/5)*(y-1-8)*-1), 800);
}
}
if (current > 800) {
canvas.renderAll();
return;
}
canvas.renderAll();
fabric.util.requestAnimFrame(animate);
})();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question