Coke2Code
Coke2Code

Reputation: 197

Rotating a cocos2d sprite on an anchor point outside of the sprite

Currently the setanchor function only sets the anchor within the sprite frame. Is there any (easier) wway to change the anchor point to a coordinate on screen space? My purpose is to allow the sprite to rotate around a circle.

TIA for any suggestions made.

Upvotes: 2

Views: 3056

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

Use the Node hierarchy to your advantage. Create a new Node (which won't be visible unless you want it to be) and add your sprite to the node as children. Position the sprite child somewhat away by giving it a position of 100, 100 for example.

Now if you rotate the node using the rotation property, instead of the sprite, the sprite should rotate with the node, making it appear as if it goes around in a circle. The node itself will be the centerpoint of the rotation.

I've added this Q&A to my cocos2d FAQ: http://www.learn-cocos2d.com/knowledge-base/cocos2d-iphone-faq/learn-cocos2d-public-content/manual/cocos2d-general/14826-how-to-rotate-a-sprite-in-a-circular-motion

Upvotes: 3

Related Questions