Question

I am new to cocos2d-x and I want to get the sprite size. But here are tow functions that do the work: getContentSize and getBoundingBox. What is the difference of this functions? Should I always usegetBoundingBox`?

Was it helpful?

Solution

contentSize refers to the size of the content (ie the texture size) whereas boundingBox also takes into account that the node may be rotated, scaled, skewed.

The bounding box is axis-aligned, which means it forms the rectangle that passes through all 4 corners of the node even when rotated, scaled, skewed, etc. and thus it may be larger than contentSize if any one of these properties has been modified.

However for collision detection of rotated, scaled, skewed, etc nodes the bounding box only provides an "early out" test where not intersecting the bounding box rectangle means there can not be any collision on a more accurate level anyway. If the axis-aligned bounding box intersection test passes you usually go on to perform, for example, an oriented bounding box rectangle intersection test or one where you do a collision mask or polygon intersection test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top