Ejemplo n.º 1
0
  private void restart() {

    float y = (HEIGHT_WORLD / 2) - 10;

    planetCoreModel.setTransform(0, y, 0);
    planetCoreModel.setLinearVelocity(0f, 0f);
    planetCoreModel.setAngularVelocity(1f);

    planetModel.setTransform(0, y, 0f);
    planetModel.setLinearVelocity(0f, 0f);
    planetModel.setAngularVelocity(1f);

    Vector2 vec = new Vector2();

    for (int i = 0; i < MAX_BALLS; i++) {
      float tx = rand.nextFloat() * 1.0f - 1f;
      float ty = HEIGHT_WORLD + BALL_RADIUS;
      float angle = rand.nextFloat() * MathUtils.PI * 2;

      ballModels[i].setActive(false);
      ballModels[i].setLinearVelocity(vec.set(0, -10));
      ballModels[i].setAngularVelocity(0f);
      ballModels[i].setTransform(vec.set(tx, ty), angle);
    }

    tweenManager.killAll();

    Tween.call(
            new TweenCallback() {
              private int idx = 0;

              @Override
              public void onEvent(int arg0, BaseTween<?> arg1) {
                if (idx < ballModels.length) {
                  ballModels[idx].setAwake(true);
                  ballModels[idx].setActive(true);
                  idx += 1;
                }
              }
            })
        .repeat(MAX_BALLS, 0.5f)
        .start(tweenManager);
  }
 public void applySteering(Body body) {
   // For Kinematic & Static bodies, we set the velocity
   BodyType type = body.getType();
   if (type == BodyType.KinematicBody || type == BodyType.StaticBody) {
     body.setLinearVelocity(velocity);
     body.setAngularVelocity(rotation);
   } else {
     // body is dynamic, so we apply an impulse
     body.applyLinearImpulse(velocity, body.getWorldCenter());
     body.applyAngularImpulse(rotation);
   }
 }