requestanimationframe

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

瘦欲@ 提交于 2021-02-04 21:34:46
问题 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, my code is like this, which I don't think is entirely uncommon: function animate(elem) { var step = function (timestamp) { //Do some stuff here. if (progressedTime < totalTime) { return requestAnimationFrame(step); //This return value seems

timestamp of requestAnimationFrame is not reliable

℡╲_俬逩灬. 提交于 2021-02-04 06:51:35
问题 I think the timestamp argument passed by requestAnimationFrame is computed wrongly (tested in Chrome and Firefox). In the snippet below, I have a loop which takes approx. 300ms (you may have to tweak the number of loop iterations). The calculated delta should always be larger than the printed 'duration' of the loop. The weird thing is, sometimes it is slower sometimes not. Why? let timeElapsed = 0; let animationID; const loop = timestamp => { const delta = timestamp - timeElapsed; timeElapsed

How can code detect if running inside an animation frame?

给你一囗甜甜゛ 提交于 2021-01-27 07:40:17
问题 If some function is passed into requestAnimationFrame() , how can that function detect that it is being called inside an animation frame? f.e. function someFunction() { if (/* What goes here? */) { console.log('Inside animation frame.') } else { console.log('Not inside animation frame.') } } // The following lines should not be modified for the answer. someFunction() // logs "Not inside animation frame." requestAnimationFrame(someFunction) // eventually logs "Inside animation frame." The last

How can code detect if running inside an animation frame?

早过忘川 提交于 2021-01-27 07:40:09
问题 If some function is passed into requestAnimationFrame() , how can that function detect that it is being called inside an animation frame? f.e. function someFunction() { if (/* What goes here? */) { console.log('Inside animation frame.') } else { console.log('Not inside animation frame.') } } // The following lines should not be modified for the answer. someFunction() // logs "Not inside animation frame." requestAnimationFrame(someFunction) // eventually logs "Inside animation frame." The last

Angular component with requestAnimationFrame issue

半城伤御伤魂 提交于 2021-01-05 07:38:56
问题 im using Angular 9 together with THREE.Js. The app lets you switch between a 2D html component and a 3D ThreeJs component via button click. The 3D component creates all needed for threejs on ngAfterViewInit and calls a loop function with requestAnimationFrame . private loop() { this.AFID = requestAnimationFrame(this.loop.bind(this)) this.renderer.render(this.scene, this.camera) } The loop gets canceled as soon as all models of my scene are loaded and the onLoad callback is fired or when

Limiting framerate in Three.js to increase performance, requestAnimationFrame?

心已入冬 提交于 2020-08-17 15:57:21
问题 I was thinking that for some projects I do 60fps is not totally needed. I figured I could have more objects and things that ran at 30fps if I could get it to run smoothly at that framerate. I figured if I edited the requestAnimationFrame shim inside of three.js I could limit it to 30 that way. But I was wondering if there was a better way to do this using three.js itself as provided. Also, will this give me the kind of performance increase I am thinking. Will I be able to render twice as many

Limiting framerate in Three.js to increase performance, requestAnimationFrame?

南楼画角 提交于 2020-08-17 15:56:18
问题 I was thinking that for some projects I do 60fps is not totally needed. I figured I could have more objects and things that ran at 30fps if I could get it to run smoothly at that framerate. I figured if I edited the requestAnimationFrame shim inside of three.js I could limit it to 30 that way. But I was wondering if there was a better way to do this using three.js itself as provided. Also, will this give me the kind of performance increase I am thinking. Will I be able to render twice as many

Cancelling requestAnimationRequest in a React component using hooks doesn't work

…衆ロ難τιáo~ 提交于 2020-07-22 06:06:13
问题 I am working on a progress bar (Eventually..) and I want to stop the animation (calling cancelAnimationRequest ) when reaching a certain value (10, 100, ..., N) and reset it to 0. However, with my current code, it resets to 0 but keeps running indefinitely. I think I might have something wrong in this part of the code: setCount((prevCount) => { console.log('requestRef.current', requestRef.current, prevCount); if (prevCount < 10) return prevCount + deltaTime * 0.001; // Trying to cancel the

Is it true that if possible I should never use setInterval & setTimeout?

天涯浪子 提交于 2020-07-17 08:18:20
问题 I am learning to code in JavaScript. I am programming something with some timed mouse animation. I'm just about to add some code which draws the mouse path. It's going to be something that takes the mousemove event, and every time the mouse moves draw a new line path on Canvas. And with time, that path is going to be more transparent until it disappears. Of course, new paths are always going to be opaque so there's a continuous movement. I figured out a way I can do this with just

MediaRecorder switch video tracks

你说的曾经没有我的故事 提交于 2020-07-09 10:18:31
问题 I am using MediaRecorder API to record videos in web applications. The application has the option to switch between the camera and screen. I am using Canvas to augment stream recording. The logic involves capturing stream from the camera and redirecting it to the video element. This video is then rendered on canvas and the stream from canvas is passed to MediaRecorder . What I noticed is that switching from screen to video (and vice-versa) works fine as long as the user doesn't switch