Cocos2D help: how to rotate a sprite continuously and generate child sprites in a rotating sprite

I'm new to cocos2D, can anyone suggest an easy solution to the problem?

I have a 8-bar windmill in a windmill with each bar divided by 45 degrees, where half of the windmill is on the screen and half is off the screen. I want to turn the windmill and make it spin forever. I also want to attach the child at the end of the windmills, and he will rotate with the windmill. Easy solution will be appreciated.

EDIT

I managed to rotate the windmill, 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 a child sprite at the end of each windmill, only 8 bars, and each bar is divided into 45 degrees.

+4
source share
2 answers

To make CCSprite spin forever, you can use something like

 [windmill runAction:[CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5.0 angle:360]]]; 

then add any CCSprite as a child that will rotate too. The position that you assign to the child is based on his parent, take it into account.

EDIT 1

Well, if you know the radius of the circle, you can do some mathematical calculations and get the position you need. But also, if you do not need to calculate the positions, just try and get an error to get what you want. Try with a windmill without rotation.

+9
source

You declare your action β€œrot” as an instance of CCRotateBy, but when you select it, you start with [CCRepeatForever[...]]; If you want, you could do

CCRotateBy *rot = [CCRotateBy actionWithDuration:5 angle:360];

[windmill runAction:[CCRepeatForever actionWithAction:rot]];

+1
source

Source: https://habr.com/ru/post/1397386/


All Articles