box2d 船舶游戏初学者问题:applyForce、重力 +水
我刚刚开始使用 cocos2d + box2d。 我很想创建一个简单的 2D 船舶游戏,您可以在其中从顶部(从天空)向下观察大海和船舶。
有人可以给我一个非常非常基本的例子,如何将风应用到我的世界中?我必须对每个船体施加力吗?
那么重力呢?既然是直线下降,那我应该把它设置为0吗?重力.Set(0.0f,0.0f)?它实际上会把船拉下来..
我应该以某种方式处理水吗?例如它的密度?
I'm just starting with cocos2d + box2d.
I would love to create a simple 2d ship game where you look from top(from the sky) down at the sea with the ships.
Could someone give me a very very basic example, how to apply wind to my world? Do I have to applyForce to each ship body?
And what about the gravity? Since it goes straight down, should I set it to 0? gravity.Set(0.0f, 0.0f)? It actually would pull down the ship..
Should I somehow deal with the water? e.g with density of it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可能必须检测船只的位置,然后以某种方式对它们施加力量。
是的,将重力设置为 0。
水就根本不必是物体。就像背景图像一样。
you would probably have to detect where the ships are and then apply force on them somehow.
and yes set gravity to 0.
and water wouldn't have to be an object at all. just like a background image.
如果您从顶部看并且想要对所有船只施加风力,您可以使用重力矢量。在这种情况下,风力将自动施加到您的对象上。
如果场景中还有其他动态对象,那么最好保留指向所有飞船的指针列表(std::list 或 NSMutableArray)。请注意,默认情况下,box2D 会清除每个模拟步骤的所有力。您可以禁用此属性或在每个模拟步骤中手动施加力
If you are looking from the top and want to apply wind force to all your ships you can use gravity vector. In this case wind force will be applied to your objects automatically.
If there are other dynamic objects on the scene then it's a good idea to keep the list (std::list or NSMutableArray) of pointers to all your ships. Notice, that by default box2D is clearing all the forces each simulation step. You can disable this property or apply forces manually each simulation step