cocos2d/box2d iPhone - 随机圆形路径
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要萤火虫互相碰撞吗?
我问,好像这不是一个要求,Box2D 可能对您的需求来说太过分了。听起来 Cocos2d 是一个很好的选择,但我认为你最好研究像 boids
即使这样也可能过于复杂。将一些正弦和余弦项与一些随机缩放因子混合在一起可能就足够了。
您可以使用一个正弦/余弦组合形成一个接近屏幕大小的椭圆:
其中 randomFactor 的范围为 0.6 到 0.9
这将为您提供围绕屏幕的广泛椭圆运动,然后您可以添加更小的正弦/余弦使它们围绕椭圆上的点旋转的因素。
通过将时间增量 (t) 乘以不同的值(负值和正值),曲线的路径将以较少的几何方式移动。例如,如果您使用
椭圆形,它将变成数字 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:
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
the ellipse will turn into a figure 8. (i think!)
Hope this helps get you started. Good luck.
寻找想法的一个地方是人工生命领域。他们长期以来一直在模拟成群的实体。这里是一些用 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