Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo Sprites does not work #207

Open
samael205 opened this issue Apr 25, 2018 · 3 comments
Open

Demo Sprites does not work #207

samael205 opened this issue Apr 25, 2018 · 3 comments

Comments

@samael205
Copy link

Hi @asturur,

I know that FabricJS does not support this kind animation, but the demo Sprite does not work, Tested on Mozilla Firefox and Chrome.

Now i have the next question:

In the demos page of fabricjs, I have replicated in my project the animated sprite demo
This code is based on a custom class that allows you to work with an array of images to generate the animation of the sprite, but for it to work you have to execute the following code.

This creates as a kind of setInterval of every 0.6 seconds to give the feeling that there is movement in the animation. This code works

I assume that the next function
(function render() { canvas.renderAll(); fabric.util.requestAnimFrame(render); })();

It works as a setInterval of JavaScript, in which the call is repeated every X time, and I can, in the setInterval if I add it to a variable, set the variable to null to stop the setInterval.
Can this be done with requestAnimFrame (reder)?. I need this because I need to stop this function at a certain time.

@asturur
Copy link
Member

asturur commented Apr 25, 2018

So i did not do the original sprite code demo.
What i would do would be create 2 custom method in this class, called start and stop.

Start would start a chained requestRenderAll to continuosly re render the frame, and stop would stop it. using requestRenderAll would avoid rendering multiple times since each call cancel the previous one.

Let me see if i can update this demo with the concept

@andrejpavlovic
Copy link

play: function() {
var _this = this;
this.animInterval = setInterval(function() {
_this.onPlay && _this.onPlay();
_this.spriteIndex++;
if (_this.spriteIndex === _this.spriteImages.length) {
_this.spriteIndex = 0;
}
}, 100);
},

Setting dirty flag seems to help with the rendering

     _this.spriteIndex++; 
     if (_this.spriteIndex === _this.spriteImages.length) { 
       _this.spriteIndex = 0; 
     } 
     _this.set('dirty', true);
   }, 100); 

@asturur
Copy link
Member

asturur commented Oct 3, 2018

i tried to fix last day but i was writing 'this' instead of '_this'. ok i ll pish it up now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants