I am wondering if there is any simple tool within Cocos for automatically determining if a sprite is visible. I could code up a bunch of logic on my own, but it would be nice if Cocos already has a simple test built-in to see whether a sprite is visible or otherwise hidden behind another sprite. Since Cocos has many other tools that obviate the need for custom logic in many places, this would seem like a likely part of that toolset, but I cannot find anything so far in my searching.
It would be a simple case of having it test if the bounding box for all sprites with a higher z setting are covering or hiding the bounding box of the sprite in question.
You can use this function to determine if two rects (the bounding boxes of the sprites) intersects:
and then calculate the z-order.
If you want to be more precise you can calculate an index to know how much the first sprite cover the second:
CGRectIntersectioncalculate the rectangle generated by the intersection of the other two.If Index is 1 the two rectangles are precisely one above the other.