如何检查精灵对象是否可见?

发布于 2024-10-08 18:07:12 字数 161 浏览 0 评论 0原文

我有一个包含以下方法的 Sprite 类数组:xywidthheight。它们根据他的 z 属性进行排序。最后一个在上面。我也有屏幕尺寸。我如何知道特定的精灵是否可见?

I have a Array of Sprite classes with these methods: x, y, width and height. They are sorted based on his z property. The last are on top. I have, too, the screen size. How can I know if a specific Sprite are visible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

檐上三寸雪 2024-10-15 18:07:12

“使其工作”的最简单方法是以反向 Z 顺序渲染。这是最接近的最后一个。

否则你就会遇到寻找遮挡的 N^2 问题。您可以通过构建遮挡树来优化这一点。

另一种选择可能是深度测试缓冲区。

class Sprite
  def occluded?(other)
    # check collision in X and Y
    # if they are colliding and self.z < other.z then self is partially or fully occluded
  end
end

The easiest way to "make it work" is to render in reverse Z order. That is closest last.

Otherwise you have an N^2 problem of finding occlusion. You optimize this by building occlusion trees.

Another option might be depth testing the buffer.

class Sprite
  def occluded?(other)
    # check collision in X and Y
    # if they are colliding and self.z < other.z then self is partially or fully occluded
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文