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
精彩评论