mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
* Abstracting text API to enable custom renderers * Addressing comments * Lint * Update doc/text.md Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com> * Adding dartdoc about TextRenderer Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
49 lines
978 B
Dart
49 lines
978 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/timer.dart';
|
|
import 'package:flame/gestures.dart';
|
|
|
|
class TimerGame extends Game with TapDetector {
|
|
final TextPaint textConfig = TextPaint(
|
|
config: const TextPaintConfig(
|
|
color: Color(0xFFFFFFFF),
|
|
),
|
|
);
|
|
late Timer countdown;
|
|
late Timer interval;
|
|
|
|
int elapsedSecs = 0;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
countdown = Timer(2);
|
|
interval = Timer(
|
|
1,
|
|
callback: () => elapsedSecs += 1,
|
|
repeat: true,
|
|
);
|
|
interval.start();
|
|
}
|
|
|
|
@override
|
|
void onTapDown(_) {
|
|
countdown.start();
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
countdown.update(dt);
|
|
interval.update(dt);
|
|
}
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
textConfig.render(
|
|
canvas,
|
|
'Countdown: ${countdown.current}',
|
|
Vector2(10, 100),
|
|
);
|
|
textConfig.render(canvas, 'Elapsed time: $elapsedSecs', Vector2(10, 150));
|
|
}
|
|
}
|