Will rendering images outside an HTML5 canvas hurt performance?

六眼飞鱼酱① 提交于 2021-02-05 09:31:58

问题


I'm building a 2D platformer game and I'll have a bunch of the level off the screen. Will it hurt performance to render these, or should I develop some form of 2D occlusion culling to avoid rendering this? Furthermore, how much of a performance hit would this cause?


回答1:


The rendering engine should throw out render calls to areas outside the canvas, but I would still recommend not trying to draw to those areas to begin with just to reduce the overall overhead of performing unnecessary logic. That said, the major cost would be if repaints were triggered, which in this case would not likely happen.

Here is a WebKit bug report (FIXED) from 2010 that addresses an issue where the browser was accidentally drawing things outside the canvas:

https://bugs.webkit.org/show_bug.cgi?id=45792



来源:https://stackoverflow.com/questions/21843164/will-rendering-images-outside-an-html5-canvas-hurt-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!