Skip to content

Commit

Permalink
test: Test so that paused gameloop doesn't count dt (#2731)
Browse files Browse the repository at this point in the history
Just adds a test that makes sure that the dt that has passed when a game
is paused is not accumulated.
  • Loading branch information
spydon committed Sep 11, 2023
1 parent 6f188f9 commit db15697
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/flame/test/game/game_widget/game_widget_pause_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ class _WrapperState extends State<_Wrapper> {

class _MyGame extends FlameGame {
int callCount = 0;
double timePassed = 0;

@override
void update(double dt) {
super.update(dt);
timePassed += dt;

callCount++;
}
Expand Down Expand Up @@ -150,4 +152,29 @@ void main() {
expect(game.callCount, equals(2));
},
);

myGame().testGameWidget(
'will not add time to dt when paused',
verify: (game, tester) async {
const frameLength = Duration(seconds: 1);
// Run two frames.
await tester.pump(frameLength);
await tester.pump(frameLength);

game.pauseEngine();

// Run two frames when the engine is paused.
await tester.pump(frameLength);
await tester.pump(frameLength);

game.resumeEngine();
// This time will be thrown away since the ticker hasn't received its
// first timestamp yet.
await tester.pump(const Duration(seconds: 100));
await tester.pump(frameLength);

expect(game.callCount, equals(4));
expect(game.timePassed, equals(3));
},
);
}

0 comments on commit db15697

Please sign in to comment.