Rotation in Cocos2d-x

Rotation in Cocos2d-x
0.0 0


I have created a batchNode, added it to the layer, and added a sprite to the batch node. I set the position of the batch node to the middle of the screen (otherwise, the image is placed at 0,0 only showing the upper-right quarter). I now want to rotate the sprite around itself. If I simply rotate the sprite, it rotates around the anchor point of the parent (the batch node) giving undesired results. I tried changing anchor points but it didn’t help. Here is the code used:

CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create( “donut.pvr.ccz”);
>setPosition(ccp(s.width/2,s.height/2)); // s is the size of screen

CCSprite* sprite = CCSprite::createWithSpriteFrameName;

sprite->runAction(rotateAction); // this simply rotates the sprite. sprite should rotate around itself (it’s middle)

Please suggest a solution of the problem. Is there a way to ignore the anchor points of the parent when rotating the sprite?



If you want to get rotation in the middle then your sprite must have anchor point of x: 0.5, y: 0.5. The parent should have anchor point of x: 0, y: 0.