mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
* `TextPaint` to use `TextStyle` instead of `TextPaintConfig` * Update packages/flame/lib/src/text.dart Co-authored-by: Pasha Stetsenko <stpasha@google.com> * Removed BaseTextConfig and TextPaintConfig * Update text docs * Apply suggestions from code review Co-authored-by: Erick <erickzanardoo@gmail.com> * Remove generics * Update TextBoxExample * Update text examples variable names * Fix TextPaint in collision_detection example Co-authored-by: Pasha Stetsenko <stpasha@google.com> Co-authored-by: Erick <erickzanardoo@gmail.com>
50 lines
1.0 KiB
Dart
50 lines
1.0 KiB
Dart
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
import 'package:flame/timer.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class TimerGame extends FlameGame with TapDetector {
|
|
final TextPaint textConfig = TextPaint(
|
|
style: const TextStyle(color: Colors.white),
|
|
);
|
|
late Timer countdown;
|
|
late Timer interval;
|
|
|
|
int elapsedSecs = 0;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
await super.onLoad();
|
|
countdown = Timer(2);
|
|
interval = Timer(
|
|
1,
|
|
callback: () => elapsedSecs += 1,
|
|
repeat: true,
|
|
);
|
|
interval.start();
|
|
}
|
|
|
|
@override
|
|
void onTapDown(_) {
|
|
countdown.start();
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
super.update(dt);
|
|
countdown.update(dt);
|
|
interval.update(dt);
|
|
}
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
super.render(canvas);
|
|
textConfig.render(
|
|
canvas,
|
|
'Countdown: ${countdown.current}',
|
|
Vector2(10, 100),
|
|
);
|
|
textConfig.render(canvas, 'Elapsed time: $elapsedSecs', Vector2(10, 150));
|
|
}
|
|
}
|