(週末,做的事情比較簡單。)
update(double dt) {
    super.update(dt);
    Vector2 g = world.gravity;
    g.rotate(dt/2);
  }
  List<Component> createBoundaries() {
    final visibleRect = camera.visibleWorldRect;
    final topLeft = visibleRect.topLeft.toVector2();
    final topCenter = visibleRect.topCenter.toVector2() + Vector2(0, 10);
    final topRight = visibleRect.topRight.toVector2();
    final bottomRight = visibleRect.bottomRight.toVector2();
    final bottomCenter = visibleRect.bottomCenter.toVector2() + Vector2(0, -10);
    final bottomLeft = visibleRect.bottomLeft.toVector2();
    return [
      Wall(topLeft, topCenter),
      Wall(topCenter, topRight),
      Wall(topRight, bottomRight),
      Wall(bottomLeft, bottomCenter),
      Wall(bottomCenter, bottomRight),
      Wall(topLeft, bottomLeft),
    ];
  }
這個範例設定為「重力方向每秒會旋轉90度」。
(rotate這個函數輸入的數值是以「180度」為「1單位」,而每次轉動完,BodyComponent的角度會維持在轉動後的數值,也就是說「會累積」。如果用dt作為轉動數值輸入,那每秒就會轉一圈,將輸入的數值除以二,則會變成每兩秒轉一圈。)
然後修改為兩顆球,同時遊戲邊界不是個正四邊行,而是朝中央突起的六邊型。
果然,重力也可以隨時在遊戲過程中修改,而不是只能受限於初始值。
(這個特性可以拿來做出「創意撞球遊戲」。)