mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
Debug mode to be variable on BaseGame (#608)
* Debug mode to be variable on BaseGame * Update debug mode docs * Fix typo Co-authored-by: Erick <erickzanardoo@gmail.com>
This commit is contained in:
@ -28,6 +28,7 @@
|
||||
- Remove Resizable mixin
|
||||
- Use config defaults for TextBoxComponent
|
||||
- Fixing Game Render Box for flutter >= 1.25
|
||||
- DebugMode to be variable instead of function on BaseGame
|
||||
|
||||
## 1.0.0-rc3
|
||||
- Fix TextBoxComponent rendering
|
||||
|
||||
@ -13,8 +13,7 @@ class MyGame extends Game with FPS {
|
||||
|
||||
## BaseGame features
|
||||
|
||||
Flame provides some features for debugging, these features are enabled when the method `debugMode` from the `BaseGame` class is overridden, and returning `true`. When it's enabled all `PositionComponent`s will be wrapped into a rectangle, and have its position rendered on the screen, so you can visually verify the component boundaries and position.
|
||||
|
||||
In addition to the debugMode, you can also ask `BaseGame` to record the fps(the `BaseGame` used the [FPSCounter](fps-counter) mixin). To enable it you have to override the `recordFps` method to return `true`, by doing so, you can access the current fps by using the method `fps`.
|
||||
Flame provides some features for debugging, these features are enabled when the `debugMode` from the `BaseGame` class is set to `true` (or overridden to be true).
|
||||
When it's enabled all `PositionComponent`s will be wrapped into a rectangle, and have its position rendered on the screen, so you can visually verify the component boundaries and position.
|
||||
|
||||
To see a working example of the debugging features of the `BaseGame`, [check this example](/doc/examples/debug).
|
||||
|
||||
@ -47,7 +47,7 @@ class MyGame extends BaseGame {
|
||||
ParentSquare _parent;
|
||||
|
||||
@override
|
||||
bool debugMode() => true;
|
||||
bool debugMode = true;
|
||||
|
||||
MyGame() {
|
||||
_parent = ParentSquare(Vector2.all(200), Vector2.all(300));
|
||||
|
||||
@ -62,7 +62,7 @@ class MyGame extends BaseGame {
|
||||
final fpsTextConfig = TextConfig(color: const Color(0xFFFFFFFF));
|
||||
|
||||
@override
|
||||
bool debugMode() => true;
|
||||
bool debugMode = true;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
@ -91,7 +91,7 @@ class MyGame extends BaseGame {
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
|
||||
if (debugMode()) {
|
||||
if (debugMode) {
|
||||
fpsTextConfig.render(canvas, fps(120).toString(), Vector2(0, 50));
|
||||
}
|
||||
}
|
||||
|
||||
@ -498,13 +498,13 @@ class MyGame extends BaseGame {
|
||||
}
|
||||
|
||||
@override
|
||||
bool debugMode() => true;
|
||||
bool debugMode = true;
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
|
||||
if (debugMode()) {
|
||||
if (debugMode) {
|
||||
fpsTextConfig.render(
|
||||
canvas, '${fps(120).toStringAsFixed(2)}fps', Vector2(0, size.y - 24));
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ class BaseGame extends Game with FPSCounter {
|
||||
);
|
||||
}
|
||||
|
||||
if (debugMode() && c is PositionComponent) {
|
||||
if (debugMode && c is PositionComponent) {
|
||||
c.debugMode = true;
|
||||
}
|
||||
|
||||
@ -151,9 +151,10 @@ class BaseGame extends Game with FPSCounter {
|
||||
|
||||
/// Returns whether this [Game] is in debug mode or not.
|
||||
///
|
||||
/// Returns `false` by default. Override to use the debug mode.
|
||||
/// You can use this value to enable debug behaviors for your game, many components show extra information on screen when on debug mode
|
||||
bool debugMode() => false;
|
||||
/// Returns `false` by default. Override it, or set it to true, to use debug mode.
|
||||
/// You can use this value to enable debug behaviors for your game and many components will
|
||||
/// show extra information on the screen when debug mode is activated
|
||||
bool debugMode = false;
|
||||
|
||||
/// Returns the current time in seconds with microseconds precision.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user