I am new to cocos2D can anyone suggest an easy solution to the problem?
I have a windmill with 8 bars on the windmill with each bar separated by 45 degrees, where half of the windmill is on screen and half is outside the screen. I want to rotate the windmill and make it rotate forever. Also I want to attach a child at the end of the windmill bars and it will rotate along with the windmill. An easy solution would be appreciated.
EDIT
I was able to rotate the windmill with, I wrote this piece of code:
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];
CCRotateBy *rot = [CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5 angle: 360]];
[windmill runAction:rot];
Now please help me on how to add child sprite at the end of each windmill bars, there are 8 bars in total and each bar is separated by 45 degrees.
To make a CCSprite to rotate forever you could use something like
[windmill runAction:[CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5.0 angle:360]]];
then add any CCSprite as a child it will rotate too. The position that you assign to a child is based on his parent, take that in account.
EDIT 1
Well, if you know the radius of the circle you can make some maths and get the position that you want. But also, if you don't need to calculate the positions, just try & error to get what you want. Try with the windmill without rotation.
You declare your action, "rot" as an instance of CCRotateBy yet when you allocate it, you begein with [CCRepeatForever[...]];
If you wanted you could do
CCRotateBy *rot = [CCRotateBy actionWithDuration:5 angle:360];
[windmill runAction:[CCRepeatForever actionWithAction:rot]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With