开发者

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜