0

我想使用 MT4J 开发一个应用程序。我想要实现的场景就像

  1. 屏幕上的多个球。
  2. 可以使用触摸将球放置在任何地方。

以上几点现在实现了我面临的最重要的一点 3. 重力在容器的中心,所以球被吸引到中心。

请帮助我如何实现重心?所以那个球被吸引到中心。

希望你明白我想知道的如果你不明白我请让我知道我会分享更多细节。

4

1 回答 1

0

Sure. The first thing I would recommend is that you check out the example "Physics Playground" application that comes with MT4j. This will show you how to assign physical bodies to components, and how to set up a physics simulation engine with jBox2d. But I have a feeling that you have already done that, I just wanted to be sure :)

So, back to your question. You shouldn't think about your problem in terms of gravity but rather joints. Joints allow one component to affect the physical behavior of another component, and that's what you are looking for. So try creating an invisible, static, non-collide-able component in the center of your container, and then add (and remove) joints from this component with your balls that are moving around the screen.

Specifically, check out distance joints in the Box2d manual (http://box2d.org/manual.pdf , Section 8.5). You want to create a distance joint that has a distance of 0, and then play around with the dampening ratio and frequency to get the behavior you are looking for.

Also, if jBox2d is giving you problems, consider upgrading to the newest version. It might require that you do a little debugging in the mt4j source code to get it working, but it can be definitely worth it to have a more stable physics engine, more features, and up-to-date documentation which actually corresponds to the code.

于 2014-09-24T08:53:01.233 回答