mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
adding debug component
This commit is contained in:
34
lib/components/debug_component.dart
Normal file
34
lib/components/debug_component.dart
Normal file
@ -0,0 +1,34 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'component.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
|
||||
/// This is a debug component that draws a rect on its position.
|
||||
///
|
||||
/// You can add it to your game to find out the position of something that's not normally rendered (like a hitbox or point o interaction).
|
||||
/// It will render a rectangle of ([width], [height]) on the position([x], [y]), of color [color].
|
||||
class DebugComponent extends PositionComponent {
|
||||
/// The color of the rectangle (defaults to magenta).
|
||||
Color color = const Color(0xFFFF00FF);
|
||||
|
||||
/// The actual paint used; by default it paints with stroke only and [color].
|
||||
Paint get paint => new Paint()
|
||||
..color = color
|
||||
..style = PaintingStyle.stroke;
|
||||
|
||||
/// Don't do anything (change as desired)
|
||||
void update(double t) {}
|
||||
|
||||
/// Renders the recatangle
|
||||
void render(Canvas c) {
|
||||
prepareCanvas(c);
|
||||
c.drawRect(new Rect.fromLTWH(0.0, 0.0, width, height), paint);
|
||||
}
|
||||
|
||||
/// Don't do anything (change as desired)
|
||||
void resize(Size size) {}
|
||||
|
||||
bool loaded() => true;
|
||||
bool destroy() => false;
|
||||
bool isHud() => false;
|
||||
}
|
||||
Reference in New Issue
Block a user