feat: Add HasTimeScale mixin (#2431)

This PR adds a new mixin on Component. When attached to a component, it allows scaling the delta time of that component as well as all its children by a non-negative factor. The idea is to allows slowing down or speeding up the gameplay by change the scaling factor.

Note: This approach works only for framerate independent game logic. Code in update() that is not dependent on delta time will remain unaffected by time scale.
This commit is contained in:
DevKage
2023-03-28 01:31:42 +05:30
committed by GitHub
parent 158460d7c6
commit d2a8fe01fa
8 changed files with 341 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import 'package:examples/stories/components/game_in_game_example.dart';
import 'package:examples/stories/components/look_at_example.dart';
import 'package:examples/stories/components/look_at_smooth_example.dart';
import 'package:examples/stories/components/priority_example.dart';
import 'package:examples/stories/components/time_scale_example.dart';
import 'package:flame/game.dart';
void addComponentsStories(Dashbook dashbook) {
@ -67,5 +68,13 @@ void addComponentsStories(Dashbook dashbook) {
codeLink:
baseLink('components/components_notifier_provider_example.dart'),
info: ComponentsNotifierProviderExampleWidget.description,
)
..add(
'Time Scale',
(_) => const GameWidget.controlled(
gameFactory: TimeScaleExample.new,
),
codeLink: baseLink('components/time_scale_example.dart'),
info: TimeScaleExample.description,
);
}