mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-29 16:05:47 +08:00
feat: Add FpsComponent and FpsTextComponent (#1595)
This commit is contained in:
@ -8,7 +8,7 @@ import 'package:flame/sprite.dart';
|
||||
import 'package:flame/timer.dart' as flame_timer;
|
||||
import 'package:flutter/material.dart' hide Image;
|
||||
|
||||
class ParticlesExample extends FlameGame with FPSCounter {
|
||||
class ParticlesExample extends FlameGame {
|
||||
static const String description = '''
|
||||
In this example we show how to render a lot of different particles.
|
||||
''';
|
||||
@ -25,9 +25,6 @@ class ParticlesExample extends FlameGame with FPSCounter {
|
||||
Timer? spawnTimer;
|
||||
final StepTween steppedTween = StepTween(begin: 0, end: 5);
|
||||
final trafficLight = TrafficLightComponent();
|
||||
final TextPaint fpsTextPaint = TextPaint(
|
||||
style: const TextStyle(color: Colors.white),
|
||||
);
|
||||
|
||||
/// Defines the lifespan of all the particles in these examples
|
||||
final sceneDuration = const Duration(seconds: 1);
|
||||
@ -482,22 +479,6 @@ class ParticlesExample extends FlameGame with FPSCounter {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool debugMode = true;
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
|
||||
if (debugMode) {
|
||||
fpsTextPaint.render(
|
||||
canvas,
|
||||
'${fps(120).toStringAsFixed(2)}fps',
|
||||
Vector2(0, size.y - 24),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns random [Vector2] within a virtual grid cell
|
||||
Vector2 randomCellVector2() {
|
||||
return (Vector2.random() - Vector2.random())..multiply(cellSize);
|
||||
|
||||
Reference in New Issue
Block a user