我应该在渲染到HTML5 canvas之前选择元素,或者让画布剔除 [英] Should I cull elements before rendering to HTML5 canvas or let the canvas cull

查看:199
本文介绍了我应该在渲染到HTML5 canvas之前选择元素,或者让画布剔除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该在调用画布绘制方法之前剔除元素,或者让画布处理剔除。我应该实现逻辑如:

Should I cull elements before calling the canvas draw methods or let the canvas handle culling. Should I implement logic like:

if(circle.x+circle.radius>=0 || circle.x-circle.radius<canvas.width || circle.y+circle.radius>=0 || circle.y-circle.radius<canvas.height)
  context.arc(circle.x,circle.y,circle.radius,0,2.Math.PI,false);

.arc,让画布找出要画的是什么?

should I just call context.arc and let the canvas figure out what to draw or not?

我希望这有意义吗?我会写一些代码来测试这个,但任何输入都会赞赏....谢谢。

I hope this makes sense? I will be writing some code to test this but any input would be appreciated.... Thanks.

推荐答案

Canvas即浏览器内部)将检查这些值,而不管在任何情况下,如果值在边界外(或只使用系统的低级剪辑能力的位图)执行剪切。

"Canvas" (ie. browser internals) will check these values regardless in any case and perform clipping if values are outside boundaries (or just use the system's low-level clipping ability for bitmaps).

因为这个原因,没有必要在JS中进行边界检查,而且还因为内部检查比在JS中执行边界检查更有效。

For that reason there is no point doing boundary checks in JS first, but also because the internal checks are more efficient than doing it in JS.

画布图设计为是相当安全的,不仅执行剪切,而且钳制颜色值等。

Canvas drawing is designed to be pretty safe and does not only perform clipping, but also clamps color values and so forth.

这篇关于我应该在渲染到HTML5 canvas之前选择元素,或者让画布剔除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆