My problem: I have created a parent sprite which rotates forever. I have created a child sprite to it which I want to move along with the parent sprite but not rotate it. My scenario exactly is that the parent sprite is a windmill and I am rotating it, but the child sprite is a bucket at the end of one windmill bar. So when the windmill rotates, I want the bucket to just move in that motion, where as now its moving and also rotating which looks unrealistic.
Here is the code:
CGSize winSize = [CCDirector sharedDirector].winSize;
windmill = [CCSprite spriteWithFile:@"Chorki.png"];
windmill.position = CGPointMake(winSize.width*0.02f, winSize.height*0.56f);
windmill.scale = 0.55f;
[self addChild:windmill z:0];
//Add windmill sprite on screen
CCRotateBy *rot = [CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5 angle: 360]];
[windmill runAction:rot];
//The above code to rotate windmill, the next code is to add child sprite of bucket
CCSprite *bucket1 = [CCSprite spriteWithFile:@"BucketBug.png"];
bucket1.position = ccp(235, 490.2f);
[windmill addChild:bucket1 z:-1];
EDIT 1:
Sorry I forgot to show the code to rotate the sprite. Now its added.
Take a look at the ccHonorParentTransform enum:
It is set through the following property of CCNode:
Note that this will only work if the sprites are in a CCSpriteBatchNode. Since mine was not, I decided to let the parent node update the child node by settings the rotation of the child equal to the opposite of its own rotation, thus keeping the child’s rotation relative to the world constant.