HTML5 的 canvas 元素是否有重绘事件?
正如标题所示,当画布元素的内容被重绘时,我需要一个通知。 这可能吗?
如果没有,重新绘制整个页面时发出通知也可以(重新绘制而不是重新加载!)。
我需要这个的原因是我想获取画布内运行的动画的当前 FPS。
As the title says, I need a notification when the content of a canvas element was redrawn.
Is this possible?
If not, a notification when the whole page was redrawn would also be ok (reDRAWN not reLOADED!).
The reason why I need this is that I want to get the current FPS of an animation running inside a canvas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Canvas 本身没有“重绘”方法或事件。该架构使得任何函数都可以在任何时候在上下文中进行绘制。然而,一个可能的解决方案是“覆盖”标记新框架绘制的特定函数。具体来说,我认为重写 context.clearRect 将是可行的方法。
此方法的唯一问题是它假设每帧调用一次clearRect。不过,只要是这样,那么上面的代码就可以工作。
Canvas itself has no "redraw" method or event. The architecture is such that at any time, any function can draw in the context. However, a possible solution would be to "override" specific functions which mark the drawing of a new frame. Specifcially, I am thinking that overridding context.clearRect would be the way to go.
The only issue with this method is that it assumes that clearRect is called exactly once every frame. However, as long as this is the case, then the above code will work.