简体   繁体   English

cocos2d/box2d iPhone - 随机圆形路径

[英]cocos2d/box2d iPhone - Random circular paths

I am experimenting with some new ideas in Cocos2D/Box2D on iPhone.我正在 iPhone 上的 Cocos2D/Box2D 中尝试一些新想法。

I want to animate a small swarm of fireflies moving on circular (random?) paths... the idea is that the user can capture a firefly with a net..我想为一小群在圆形(随机?)路径上移动的萤火虫制作动画......这个想法是用户可以用网捕捉萤火虫......

I have considered using gravity simulations for this but I believe it is over complicating things... my previous experience with using Bezier curves tells me that this isn't the solution either..我已经考虑过为此使用重力模拟,但我认为它过于复杂......我以前使用贝塞尔曲线的经验告诉我,这也不是解决方案......

Does anyone have any bright insights for me?有人对我有什么好的见解吗?

Thanks so much.非常感谢。

Do you need the fireflies to collide with each other?你需要萤火虫相互碰撞吗?

I ask, as if this isn't a requirement, Box2D is probably overkill for your needs.我问,好像这不是一个要求,Box2D 可能对您的需求来说太过分了。 Cocos2d is an excellent choice for this by the sounds of it, but I think you'd be better off looking into flocking algorithms like boids Cocos2d 听起来是一个很好的选择,但我认为你最好研究一下像boids这样的植绒算法

Even that may be overly complicated.即使这样也可能过于复杂。 Mix a few sin and cosine terms together with some random scaling factors will likely be enough.将一些正弦和余弦项与一些随机比例因子混合在一起可能就足够了。

You could have one sin/cosine combination forming an ellipse nearly the size of the screen:你可以有一个正弦/余弦组合形成一个接近屏幕大小的椭圆:

x = halfScreenWidth + cos (t) * halfScreenWidth * randomFactor;
y = halfScreenHeight + sin (t) * halfScreenHeight * randomFactor;

where randomFactor would be something in the realm of 0.6 to 0.9其中 randomFactor 将是 realm 中的 0.6 到 0.9

This will give you broad elliptical motion around the screen, then you could add a smaller sin/cos factor to make them swirl around the point on that ellipse.这将使您在屏幕周围进行广泛的椭圆运动,然后您可以添加一个较小的 sin/cos 因子,使它们围绕该椭圆上的点旋转。

By multiplying your time delta (t) by different values (negative and positive) the path of the curve will move in a less geometric way.通过将您的时间增量 (t) 乘以不同的值(负值和正值),曲线的路径将以较少的几何方式移动。 For example, if you use例如,如果您使用

x = halfScreenWidth + cos (2*t) * halfScreenWidth * randomFactor;

the ellipse will turn into a figure 8. (i think!)椭圆会变成数字 8。(我想!)

Hope this helps get you started.希望这有助于您入门。 Good luck.祝你好运。

One place to look for ideas would be in the domain of artificial life.寻找想法的地方之一是人造生命领域。 They have been simulating swarms of entities for a long time.长期以来,他们一直在模拟大量实体。 Here is a link for some simple swarm code written in Java that should give you some ideas.这是用 Java 编写的一些简单 swarm 代码的链接,应该会给你一些想法。

http://www.aridolan.com/ofiles/Download.aspx http://www.aridolan.com/ofiles/Download.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM