Cocos2D求助:如何连续旋转一个精灵并在旋转的精灵中生成子精灵

Cocos2D help: How to rotate a sprite continuously and generate child sprites in the rotating sprite(Cocos2D求助:如何连续旋转一个精灵并在旋转的精灵中生成子精灵)

本文介绍了Cocos2D求助:如何连续旋转一个精灵并在旋转的精灵中生成子精灵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 cocos2D 的新手,谁能建议一个简单的解决方案?

I am new to cocos2D can anyone suggest an easy solution to the problem?

我有一个风车,风车上有 8 个条,每个条相隔 45 度,其中一半在屏幕上,一半在屏幕外.我想旋转风车,让它永远旋转.另外我想在风车杆的末端附加一个孩子,它会随着风车旋转.一个简单的解决方案将不胜感激.

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.

编辑

我可以旋转风车,我写了这段代码:

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];

现在请帮助我如何在每个风车条的末尾添加子精灵,总共有 8 个条,每个条相隔 45 度.

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.

推荐答案

要让 CCSprite 永远旋转,你可以使用类似

To make a CCSprite to rotate forever you could use something like

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

然后添加任何 CCSprite 作为子项,它也会旋转.你分配给孩子的位置是基于他的父母,考虑到这一点.

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.

编辑 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.

这篇关于Cocos2D求助:如何连续旋转一个精灵并在旋转的精灵中生成子精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Cocos2D求助:如何连续旋转一个精灵并在旋转的精灵中生成子精灵

基础教程推荐