0
votes

How can I rotate a sprite around a specific point, instead of the center point?

CCSprite rotation or CCRotateTo action rotate around the center point.

I'm trying to rotate the image of a face. Rotating around the center (nose) does not look as good as rotating around a point slightly below the center (chin).

In Photoshop it's possible to change the anchor point for rotation. Can that be done in cocos2d-iphone?

2
UPDATE: I decided to make a parent layer that is larger than my sprite so that the center of the parent layer is at the anchor point on my sprite. Then just rotate the parent layer.Alex L

2 Answers

1
votes

The most obvious way would be to enlarge the size of your sprite.

If the height is 50px, and the current center rotation point is the middle (25px) and you want it to be at say, 30px, just enlarge the canvas of your sprite in photoshop so that the image gained 10px of transparent space at the bottom.

Hopefully this helps your problem, i've never seen an anchor point reference for rotation in cocos2d.

0
votes

You should change your anchorPoint accordingly.

AnchorPoint will be the center of your ccsprite rotation, it starts from left bottom (0.0,0.0) to right top (1,1). To calculate it, get the point position relative to ccsprite, and divide by the sprite size:

//anchorPoint position
float x = myRotationPosition.x/ mySprite.width;
float y = myRotationPosition.y/ mySprite.height;
mySprite.anchorPoint = cpp(x,y);
//rotate mySprite based on new anchorPoint
mySprite.rotation = 90;

Hope that helps