mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 09:39:12 +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>
36 lines
795 B
Dart
36 lines
795 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/timer.dart';
|
|
import 'package:flame/gestures.dart';
|
|
|
|
class RenderedTimeComponent extends TimerComponent {
|
|
final TextPaint textPaint = TextPaint(
|
|
config: const TextPaintConfig(
|
|
color: Color(0xFFFFFFFF),
|
|
),
|
|
);
|
|
|
|
RenderedTimeComponent(Timer timer) : super(timer);
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
textPaint.render(
|
|
canvas,
|
|
'Elapsed time: ${timer.current}',
|
|
Vector2(10, 150),
|
|
);
|
|
}
|
|
}
|
|
|
|
class TimerComponentGame extends BaseGame with TapDetector, DoubleTapDetector {
|
|
@override
|
|
void onTapDown(_) {
|
|
add(RenderedTimeComponent(Timer(1)..start()));
|
|
}
|
|
|
|
@override
|
|
void onDoubleTap() {
|
|
add(RenderedTimeComponent(Timer(5)..start()));
|
|
}
|
|
}
|