mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
* Improving TimerComponent API * pr suggestion * Update packages/flame/lib/src/components/timer_component.dart Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com> * pr suggestion * docs * pr suggestions * fixing * renaming to onTick * Update packages/flame/lib/src/components/timer_component.dart Co-authored-by: Luan Nico <luanpotter27@gmail.com> * Apply suggestions from code review Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com> * fixing issues * fixing flmae bloc isse * more suggestions * Update packages/flame/lib/src/timer.dart Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com> Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com> Co-authored-by: Luan Nico <luanpotter27@gmail.com>
40 lines
890 B
Dart
40 lines
890 B
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class RenderedTimeComponent extends TimerComponent {
|
|
final TextPaint textPaint = TextPaint(
|
|
style: const TextStyle(color: Colors.white),
|
|
);
|
|
|
|
final double yOffset;
|
|
|
|
RenderedTimeComponent(double period, {this.yOffset = 150})
|
|
: super(
|
|
period: period,
|
|
removeOnFinish: true,
|
|
);
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
textPaint.render(
|
|
canvas,
|
|
'Elapsed time: ${timer.current.toStringAsFixed(3)}',
|
|
Vector2(10, yOffset),
|
|
);
|
|
}
|
|
}
|
|
|
|
class TimerComponentGame extends FlameGame with TapDetector, DoubleTapDetector {
|
|
@override
|
|
void onTap() {
|
|
add(RenderedTimeComponent(1));
|
|
}
|
|
|
|
@override
|
|
void onDoubleTap() {
|
|
add(RenderedTimeComponent(5, yOffset: 180));
|
|
}
|
|
}
|