是requestAnimationFrame实现的递归吗?

编程入门 行业动态 更新时间:2024-10-23 01:38:33
本文介绍了是requestAnimationFrame实现的递归吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在尝试Three.js,它依赖于 requestAnimationFrame 来执行动画.

I'm currently experimenting with three.js, which relies on requestAnimationFrame to perform animations.

在调用多维数据集旋转和 renderer.render 函数之前,以下代码不会导致无限递归吗?

Wouldn't the following code result in infinite recursion before the cube rotations and renderer.render function are invoked?

function render() { requestAnimationFrame(render); cube.rotation.x += 0.1; cube.rotation.y += 0.1; renderer.render(scene, camera); } render();

该代码有效,但是我正在努力提高我对JavaScript的总体了解.

The code works, but I'm trying to improve my overall understanding of JavaScript.

我的看法是,渲染作为回调函数被调用.但这是否意味着JavaScript会继续运行之前函数中的代码,然后停止继续进行下一个调用?

The way I see it, is that render is invoked as a callback function. But does that mean that JavaScript continues running through the code in the function before stopping to move on to the next call?

推荐答案

这仅请求浏览器在下一个渲染循环之前调用您的回调:

This only requests the browser to call your callback before the next rendering loop:

准备在屏幕上更新动画时,应调用此方法.这将要求您的动画函数在浏览器执行下一次重新绘制之前被调用.

You should call this method whenever you're ready to update your animation onscreen. This will request that your animation function be called before the browser performs the next repaint.

因此这里没有递归,您的函数将继续执行.

So there is no recursion here, and your function continue with the execution.

您还可以使用 cancelAnimationFrame 取消对回调的请求.

You can also cancel the request for your callback with cancelAnimationFrame.

在此处中查找.

更多推荐

是requestAnimationFrame实现的递归吗?

本文发布于:2023-11-30 20:35:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651404.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   requestAnimationFrame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!