[英]HTML5 Canvas draw only visible images
Is it possible to "detect" and draw only visible images on HTML5 Canvas? 是否可以“检测”并在HTML5 Canvas上仅绘制可见图像? This'll make a huge performance optimisation in my game, for example if image 1 is covered by image 2, how can I only draw image 2 ?
这将在我的游戏中实现巨大的性能优化,例如,如果图像1被图像2覆盖,我怎么只能绘制图像2?
This is dumb occlusion culling, not a fancy tree ordered collection of objects like in the original DOOM and such. 这是愚蠢的遮挡剔除,而不是像原始DOOM中那样的花哨树排序的对象集合。
I have no idea whether the overhead of this method will pay off, you'll need to try it and see. 我不知道这种方法的开销是否会得到回报,您需要尝试一下看看。 There might be a missing ;
可能缺少一个; or {} or two.
或{}或两个。
count = count of all objects
for (i = 1; i < count; i++)
visible[i] = true;
for i = 0; i < count; i++
{
not_hidden = true;
for (j = 0; j < count && not_hidden; j++)
{
if ((i!= j) && visible[j]
// if j is closer/on top -- reverse this if increased depth = -z not +z
&& (z-order[j] < z-order[i])
// bounding rectangles 0,0 = top-left of screen
&& (obj[i].left <= obj[j].right) && (obj[i].right <= obj[j].right) && (obj[i].left >= obj[j].left)
&& (obj[i].top <= obj[j].bottom) && (obj[i].bottom <= obj[j].bottom) && (obj[i].top >= obj[j].top) )
{
visible[i] = false;
not_hidden = false;
}
}
}
Now only draw objects where visible[ix] is true 现在只绘制visible [ix]为true的对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.