Questions tagged [cancelanimationframe]

27 questions
1
vote
0 answers

Recoil.js Strange behavior when using recoilState for controlling animationFrame

import React, { useState, useLayoutEffect } from "react"; import { useRecoilState, atom } from "recoil"; function Counter() { const [counter, setCounter] = useState(0); //const [isPaused, setIsPaused] = useState(true); const [running,…
1
vote
2 answers

How to pause and unpause with requestAnimationFrame

So, I'm having an issue with figuring out how to pause and (most importantly) unpause my simulation. When I press play, I call a function called animate(). I only call it once, so naturally inside animate() I call requestAnimationFrame(animate) for…
1
vote
1 answer

Cancel the requestAnimationFrame loop after some time

I want to cancel an animation after a timeout. Here's my code function animate(){ id = requestAnimationFrame(animate); console.log(id); c.clearRect(0,0, window.innerWidth, window.innerHeight); for(let i = 0; i <…
1
vote
1 answer

requestAnimFrame is executed multiple times

I have an emotion detection running with openCV.js for the face detection and tensorflow.js for the emotion classification. When I start the emotion detection I call the requestAnimFrame(myProcessingLogic) function and pass my detection logic to the…
1
vote
1 answer

requestAnimationFrame with clearAnimationFrame on scroll event

There are so many questions about JavaScript's requestAnimationFrame already and (I think) I understand the concept but is there any performance difference between with and without cancelAnimationFrame in this context? // Setup a timer var…
norixxx
  • 2,549
  • 2
  • 19
  • 26
1
vote
1 answer

requestAnimationFrame runs twice as fast after cancelAnimtionFrame

I've been staring at my code for so long but i don't seem to understand what is happening. Whenever the game ends, I do a cancelAnimationFrame to stop the game. Then I boot up the menu again. Now the problem is that when I call requestAnimationFrame…
1
vote
1 answer

cancelAnimationFrame inside of object method not working

cancelAnimationFrame() does not seem to work when called inside an object's method. I have tried binding the this value to the callback function (as demonstrated on MDN with setTimeout) but I received a TypeError when using cancelAnimationFrame(). I…
1
vote
3 answers

storing requestAnimationFrame

Brief explanation: I've made a requestAnimation which alternatively has 2 callbacks depending on counter; one of the callbacks will increment counter and the other will decrease it (always looping inside a certain range 0 // arr.length). Everything…
maioman
  • 18,154
  • 4
  • 36
  • 42
1
vote
1 answer

Is there a way to cancel requestAnimationFrame without a global variable?

I'm trying to cancel a requestAnimationFrame loop, but I can't do it because each time requestAnimationFrame is called, a new timer ID is returned, but I only have access to the return value of the first call to requestAnimationFrame. Specifically,…
0
votes
1 answer

Can't cancel requestAnimationFrame and even run multiple animation simultaneously

I have an animation and it will jump into the target height, and then fall to the ground. If I click "jump" twice when it is still in the air and does not hit the target height, it will recalculate the target and continue the jump into the new…
0
votes
1 answer

Does cancelAnimationFrame clear any existing requestAnimationFrame queues?

Does cancelAnimationFrame completely removes all the queued up animation logic? For example, lets say the logic was complicated and my screen was doing 60FPS. the time it took to complete the entire logic per frame, lets say is 50ms. That is much…
0
votes
1 answer

Do I have to cancelAnimationFrame before next requestAnimationFrame?

Here I have a simple timer application in React. Do I need to always call cancelAnimationFrame before calling next requestAnimationFrame in animate method? I read from somewhere that if I call multiple requestAnimationFrame within single callback,…
0
votes
0 answers

cancelAnimationFrame and setTimeout

For the following js code: let myAnimation; setTimeout(function(){myAnimation = requestAnimationFrame(turn);}, 500); Because of scope, the following code does not work to stop the animation: btnStop.addEventListener('click',…
0
votes
1 answer

Why the js window.cancelAnimationFrame() not working?

Code Not Working :- let animateFrame ; function animate (){ if(animateFrame > 200 ) { window.cancelAnimationFrame(animateFrame ); } console.log(animateFrame ) ; animateFrame = …
0
votes
1 answer

Why cancelAnimationFrame () doesn't stop animation on MouseDown event?

Why cancelAnimationFrame () doesn't stop animation on MouseDown event? But animation stops triggered by a second click. What could be the problem? And is there a way, after premature stopping the animation, to return the current "cur" and "rez"…
1
2