0

このチュートリアルに従ってテストベッドを起動しましたが、何も起こりません。GUI は表示されますが、テストは実行されず、そこにあるだけです。テストベッドはドライバー クラスから起動され、テストベッド テストを追加します。他の誰かがこの問題を抱えていますか?

ドライバークラス

public class Driver {
public static final String GRAVITY_SETTING = "Gravity";
/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    TestbedModel model = new TestbedModel();         // create our model

    // add tests
    model.addCategory("My Tests");
    model.addTest(new MJWTest2());
    model.addTest(new VerticalStack());

    // add our custom setting "My Range Setting", with a default value of 10, between 0 and 20
    model.getSettings().addSetting(new TestbedSetting(GRAVITY_SETTING, SettingType.ENGINE, false));

    TestbedPanel panel = new TestPanelJ2D(model);    // create our testbed panel
    JFrame testbed = new TestbedFrame(model, panel, null); // put both into our testbed frame
    // etc
    testbed.setVisible(true);
    testbed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

テストベッド テストクラス

public class MJWTest2 extends TestbedTest {
    public static final String GRAVITY_SETTING = "Gravity";


    @Override
    public void initTest(boolean argDeserialized) {
        setTitle("Couple of Things Test");

        getWorld().setGravity(new Vec2());

        for (int i = 0; i < 2; i++) {
            PolygonShape polygonShape = new PolygonShape();
            polygonShape.setAsBox(1, 1);
            FixtureDef fix = new FixtureDef();
            fix.shape = polygonShape;

            BodyDef bodyDef = new BodyDef();
            bodyDef.type = BodyType.DYNAMIC;
            bodyDef.position.set(5 * i, 0);
            bodyDef.angle = (float) (Math.PI / 4 * i);
            bodyDef.allowSleep = false;
            Body body = getWorld().createBody(bodyDef);
            body.createFixture(fix);

            body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
        }
    }
@Override
public void step(TestbedSettings settings) {
    super.step(settings); // make sure we update the engine!
    TestbedSetting gravity = settings.getSetting(GRAVITY_SETTING); // grab our setting
    if (gravity.enabled) {
      getWorld().setGravity(new Vec2(0, -9));
    }
    else {
      getWorld().setGravity(new Vec2());
    }
  }

    @Override
    public String getTestName() {
        return "Couple of Things";
    }
}
4

2 に答える 2

1

wiki の更新なしでエンジンの更新がありました。おっと!ごめん。ここに示すように、コントローラーを作成して開始する必要があります 。 TestbedMain.java

于 2014-03-25T20:11:33.330 に答える
0

これを試して

public class MJWTest2 extends TestbedTest {

   @Override
   public void initTest(boolean argDeserialized) {
      setTitle("Couple of Things Test");

      getWorld().setGravity(new Vec2());

      for (int i = 0; i < 2; i++)
      {
//         CircleShape circleShape = new CircleShape();
//         circleShape.m_radius = 1;
//         Shape shape = circleShape;
         PolygonShape polygonShape = new PolygonShape();
         polygonShape.setAsBox(1, 1);
         Shape shape = polygonShape;

         BodyDef bodyDef = new BodyDef();
         bodyDef.type = BodyType.DYNAMIC;
         bodyDef.position.set(5 * i, 0);
         bodyDef.angle = (float) (Math.PI / 4 * i);
         bodyDef.allowSleep = false;
         Body body = getWorld().createBody(bodyDef);
         body.createFixture(shape, 5.0f);

         body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
      }
   }

   /**
    * @see org.jbox2d.testbed.framework.TestbedTest#getTestName()
    */
   @Override
   public String getTestName() {
      return "Couple of Things";
   }
}

いわゆる「ドライバークラス」

public class App2 {

public static final String GRAVITY_SETTING = "Gravity";

public static void main(String[] args) {
    // TODO Auto-generated method stub
    TestbedModel model = new TestbedModel();         // create our model

    // add tests
    model.addCategory("My Tests");
    model.addTest(new MJWTest2());
    model.addTest(new VerticalStack());

    // add our custom setting "My Range Setting", with a default value of 10, between 0 and 20
    model.getSettings().addSetting(new TestbedSetting(GRAVITY_SETTING, SettingType.ENGINE, false));

    TestbedPanel panel = new TestPanelJ2D(model);    // create our testbed panel
    JFrame testbed = new TestbedFrame(model, panel); // put both into our testbed frame
    // etc
    testbed.setVisible(true);
    testbed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
}

私にとってはうまくいきました..あなたにもうまくいくことを願っています..

于 2016-09-21T15:33:03.650 に答える