开发者

How to check if a sprite object is visible?

开发者 https://www.devze.com 2023-01-31 10:51 出处:网络
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 scr开发者_开发知识库een size. How can I know

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 scr开发者_开发知识库een size. How can I know if a specific Sprite are visible?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消