Files
flame/packages/flame_oxygen/example/lib/system/debug_system.dart
Jochum van der Ploeg c015af8bee Added flame_oxygen (#823)
* Added flame_oxygen

* Reworked structure

* Added components and example

* Added particle support

* Updated code

* Update example

* Fixed mistake

* Update

* Updated documentation

* Added system documentation

* Fixed line length

* Added most components docs

* Docs done?

* Update doc/oxygen.md

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Added GameRef

* Fixed GameRef

* Reworked library to not use part system

* Added GameRef docs

* Removed library line

* Updated CHANGELOG

* Added License

* Fixed linting problem

* Update packages/flame_oxygen/example/lib/main.dart

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>

* Update after review from spydon

* Added flipping

* Fixed CI/CD

* Fix

* Update

* Update doc/oxygen.md

Co-authored-by: Renan <6718144+renancaraujo@users.noreply.github.com>

Co-authored-by: Erick <erickzanardoo@gmail.com>
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
Co-authored-by: Renan <6718144+renancaraujo@users.noreply.github.com>
2021-09-05 23:44:29 +02:00

64 lines
1.5 KiB
Dart

import 'package:flame/game.dart';
import 'package:flame_oxygen/flame_oxygen.dart';
import 'package:flutter/material.dart';
class DebugSystem extends BaseSystem {
final debugPaint = Paint()
..color = Colors.green
..style = PaintingStyle.stroke;
final textPainter = TextPaint(
config: const TextPaintConfig(
color: Colors.green,
fontSize: 10,
),
);
final statusPainter = TextPaint(
config: const TextPaintConfig(
color: Colors.green,
fontSize: 16,
),
);
@override
List<Filter<Component>> get filters => [];
@override
void render(Canvas canvas) {
super.render(canvas);
statusPainter.render(
canvas,
[
'FPS: ${(world!.game as FPSCounter).fps()}',
'Entities: ${world!.entities.length}',
].join('\n'),
Vector2.zero(),
);
}
@override
void renderEntity(Canvas canvas, Entity entity) {
final size = entity.get<SizeComponent>()!.size;
canvas.drawRect(Vector2.zero() & size, debugPaint);
textPainter.render(
canvas,
[
'position: ${entity.get<PositionComponent>()!.position}',
'size: $size',
'angle: ${entity.get<AngleComponent>()?.radians ?? 0}',
'anchor: ${entity.get<AnchorComponent>()?.anchor ?? Anchor.topLeft}',
].join('\n'),
Vector2(size.x + 2, 0),
);
textPainter.render(
canvas,
entity.name ?? '',
Vector2(size.x / 2, size.y + 2),
anchor: Anchor.topCenter,
);
}
}