From 90fe03dc32c9bda36b494a44f28ac008eee9bf1d Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Wed, 6 Jan 2021 00:20:52 +0100 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + doc/debug.md | 5 ++--- doc/examples/composability/lib/main.dart | 2 +- doc/examples/debug/lib/main.dart | 4 ++-- doc/examples/particles/lib/main.dart | 4 ++-- lib/game/base_game.dart | 9 +++++---- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 705945c55..617c94872 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/doc/debug.md b/doc/debug.md index 234f338a0..017999dce 100644 --- a/doc/debug.md +++ b/doc/debug.md @@ -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). diff --git a/doc/examples/composability/lib/main.dart b/doc/examples/composability/lib/main.dart index 7136f542a..e647aeb03 100644 --- a/doc/examples/composability/lib/main.dart +++ b/doc/examples/composability/lib/main.dart @@ -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)); diff --git a/doc/examples/debug/lib/main.dart b/doc/examples/debug/lib/main.dart index c9c9b5d82..16aeeeb49 100644 --- a/doc/examples/debug/lib/main.dart +++ b/doc/examples/debug/lib/main.dart @@ -62,7 +62,7 @@ class MyGame extends BaseGame { final fpsTextConfig = TextConfig(color: const Color(0xFFFFFFFF)); @override - bool debugMode() => true; + bool debugMode = true; @override Future 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)); } } diff --git a/doc/examples/particles/lib/main.dart b/doc/examples/particles/lib/main.dart index 85a00bfed..7c83673f8 100644 --- a/doc/examples/particles/lib/main.dart +++ b/doc/examples/particles/lib/main.dart @@ -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)); } diff --git a/lib/game/base_game.dart b/lib/game/base_game.dart index 21b654cbe..ac8be53d2 100644 --- a/lib/game/base_game.dart +++ b/lib/game/base_game.dart @@ -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. ///