Sprite bounding box logic help

Can anyone help me understand how I might check to make sure that a Sprite’s bounding box is completely inside another Sprites bounding box?

I know how to decide it a touch is within a Sprites Bounding box, but how can I check to see if one sprite is completely contained within another?

I want to make sure that Sprite B’s bounding box is completely inside Sprite A’s bounding box. Something like a ‘containsRect’ function.

fast detech using ccpDistance

can you explain a little more what you mean here?

like gran the distance between Sprite A and Sprite B and see if it is positive or negative to decide if is within or partially outside the bounds?

1 Like

Use CCRect’s containsPoint on each of the corners of the smaller rect:

bool contained = BigRect.containsPoint(CCPointMake(SmallRect.getMinX(), SmallRect.getMinY()) &&
BigRect.containsPoint(CCPointMake(SmallRect.getMinX(), SmallRect.getMaxY()) &&
BigRect.containsPoint(CCPointMake(SmallRect.getMaxX(), SmallRect.getMinY()) && BigRect.containsPoint(CCPointMake(SmallRect.getMaxX(), SmallRect.getMaxY());

@Xienen, that is an interesting solution. I’ll work wit it. Thanks.