cocos2d/box2d iPhone - 随机圆形路径

发布于 2024-11-03 18:04:53 字数 208 浏览 2 评论 0原文

我正在 iPhone 上尝试 Cocos2D/Box2D 中的一些新想法。

我想制作一小群在圆形(随机?)路径上移动的萤火虫动画...这个想法是用户可以用网捕获萤火虫。

我已经考虑过为此使用重力模拟,但我认为这过于复杂事情......我以前使用贝塞尔曲线的经验告诉我,这也不是解决方案......

有人对我有任何聪明的见解吗?

非常感谢。

I am experimenting with some new ideas in Cocos2D/Box2D on iPhone.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天旳寂寞 2024-11-10 18:04:53

你需要萤火虫互相碰撞吗?

我问,好像这不是一个要求,Box2D 可能对您的需求来说太过分了。听起来 Cocos2d 是一个很好的选择,但我认为你最好研究像 boids

即使这样也可能过于复杂。将一些正弦和余弦项与一些随机缩放因子混合在一起可能就足够了。

您可以使用一个正弦/余弦组合形成一个接近屏幕大小的椭圆:

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

其中 randomFactor 的范围为 0.6 到 0.9

这将为您提供围绕屏幕的广泛椭圆运动,然后您可以添加更小的正弦/余弦使它们围绕椭圆上的点旋转的因素。

通过将时间增量 (t) 乘以不同的值(负值和正值),曲线的路径将以较少的几何方式移动。例如,如果您使用

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

椭圆形,它将变成数字 8。(我认为!)

希望这可以帮助您入门。祝你好运。

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

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

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.

By multiplying your time delta (t) by different values (negative and positive) the path of the curve will move in a less geometric way. For example, if you use

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

the ellipse will turn into a figure 8. (i think!)

Hope this helps get you started. Good luck.

一个人的夜不怕黑 2024-11-10 18:04:53

寻找想法的一个地方是人工生命领域。他们长期以来一直在模拟成群的实体。这里是一些用 Java 编写的简单群代码的链接,应该可以给您一些想法。

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

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文