CCSprite boundingBoxInPixels() and getPositionInPixels() returns different values

Hi,

This functions returns the followings values for the same CCSprite:

boundingBoxInPixels() returns: origin{x=9.0000000 y=181.00000}, size{width=22.000000 height=38.000000}
getPositionInPixels() returns: position{x=20.000000 y=200.00000}

Why x and y are different: x(9,20) y(181,200) ?

just a guess, but maybe getPositionInPixels is returning the position of the anchor point, which by default is the center of the sprite, and boundingBoxInPixels returns the position of one of the points of the box( lower left by your coordinates )
try yourSprite.setAnchorPoint(ccp(0,0)); and then check the positions, note that this would put the sprite in a slightly different position than with the default anchor point.

That’s right. :slight_smile:
game dev wrote:

just a guess, but maybe getPositionInPixels is returning the position of the anchor point, which by default is the center of the sprite, and boundingBoxInPixels returns the position of one of the points of the box( lower left by your coordinates )
try yourSprite.setAnchorPoint(ccp(0,0)); and then check the positions, note that this would put the sprite in a slightly different position than with the default anchor point.