I’m trying to create a rotatable sprite. The rotation will be controlled by a child sprite that will be able to move along a circumference of a circle.
I’m thinking of something like this (I can’t post images, let me try to describe it):
I basically have a piece of rectangular block that I would like to rotate. Attached to this block is a knob that will control the rotation of the block. This knob is placed at a radius of 40px from the block, and it should only be able to move along the circumference of this virtual circle. User will be able to touch the knob to rotate the block.
I know how to rotate a sprite. However, I’m stumped by how to keep the knob moving along the circumference only. I’m relatively new to cocos2d and hope someone will be able to point me in the correct direction. Thanks in advance.
Add a CCNode object at the center of the block. Add your CCSprite object to that node with a position (offset) of (40,0). This puts the sprite 40 pixels to the right of the node.
Now change the rotation property of the node. The sprite now rotates around the node (ie the block center position).