Example #1
0
    @Override
    protected void bodyDefB4CreationCallback(BodyDef def) {
      super.bodyDefB4CreationCallback(def);
      //			def.linearDamping = 0.15f;
      def.linearDamping = 0.25f;
      def.isBullet = true;
      def.angularDamping = 0.9f;

      //			def.fixedRotation = true;
    }
Example #2
0
  public void create() {
    if (firstTime) {
      setCamera(0f, 10f, 10f);
      firstTime = false;
    }

    {
      PolygonDef sd = new PolygonDef();
      sd.setAsBox(50.0f, 10.0f, new Vec2(0.0f, -10.0f), 0.0f);

      BodyDef bd = new BodyDef();
      bd.position.set(0.0f, 0.0f);
      Body ground = m_world.createStaticBody(bd);
      ground.createShape(sd);

      sd.setAsBox(0.1f, 10.0f, new Vec2(20.0f, 10.0f), 0.0f);
      ground.createShape(sd);
    }

    float[] xs = {0.0f, -10.0f, -5.0f, 5.0f, 10.0f};

    for (int j = 0; j < xs.length; ++j) {
      PolygonDef sd = new PolygonDef();
      sd.setAsBox(0.5f, 0.5f);
      sd.density = 1.0f;
      sd.friction = 0.3f;

      for (int i = 0; i < 12; ++i) {
        BodyDef bd = new BodyDef();

        // For this test we are using continuous physics for all boxes.
        // This is a stress test, you normally wouldn't do this for
        // performance reasons.
        bd.isBullet = true;
        bd.allowSleep = true;

        // float32 x = b2Random(-0.1f, 0.1f);
        // float32 x = i % 2 == 0 ? -0.025f : 0.025f;
        bd.position.set(xs[j] + parent.random(-.05f, .05f), 0.752f + 1.54f * i);
        // bd.position.Set(xs[j], 2.51f + 4.02f * i);
        Body body = m_world.createDynamicBody(bd);

        body.createShape(sd);
        body.setMassFromShapes();
      }
    }
  }
Example #3
0
 @Override
 protected void bodyDefB4CreationCallback(BodyDef def) {
   def.isBullet = true;
   super.bodyDefB4CreationCallback(def);
 }