Skip to content

Commit

Permalink
fix: Null gravity override by Forge2dGame (#3092)
Browse files Browse the repository at this point in the history
`Forge2dGame` overrides the world's gravity even when a gravity vector
is not provided to it. This causes the world to use the default gravity.
  • Loading branch information
ufrshubham committed Mar 23, 2024
1 parent 0028b5c commit 3c35d59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flame_forge2d/lib/forge2d_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Forge2DGame<T extends Forge2DWorld> extends FlameGame<T> {
ContactListener? contactListener,
double zoom = 10,
}) : super(
world: ((world?..gravity = gravity) ??
world: ((world?..gravity = gravity ?? world.gravity) ??
Forge2DWorld(
gravity: gravity,
contactListener: contactListener,
Expand Down
6 changes: 6 additions & 0 deletions packages/flame_forge2d/test/forge2d_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ void main() {
game.camera.viewfinder.zoom,
);
});

test("Game does not override World's gravity with null", () {
final game = Forge2DGame(world: Forge2DWorld(gravity: Vector2(10, 0)));
expect(game.world.gravity.x, 10);
expect(game.world.gravity.y, 0);
});
},
);
}

0 comments on commit 3c35d59

Please sign in to comment.