From c8dc0b45c5e8d870183ac090a5bf02bd85ecae09 Mon Sep 17 00:00:00 2001 From: Erick Date: Sun, 17 Jan 2021 11:21:37 -0300 Subject: [PATCH] Removing initialDimensions and removeGesture methods (#627) * Removing initialDimensions and removeGesture methods * Removing wrongly commited folder * PR suggestion --- CHANGELOG.md | 1 + doc/examples/debug/lib/main.dart | 1 - doc/text.md | 11 +++-------- doc/util.md | 10 ---------- lib/util.dart | 34 -------------------------------- 5 files changed, 4 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6f4cb940..14fe2e4f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Adding loading methods for the different `ParallaxComponent` parts and refactor how the delta velocity works - Add tests for `Timer` and fix a bug where `progress` was not reported correctly - Updated the `widgets.md` documentation + - Removing methods `initialDimensions` and `removeGestureRecognizer` to avoid confusion ## 1.0.0-rc5 - Option for overlays to be already visible on the GameWidget diff --git a/doc/examples/debug/lib/main.dart b/doc/examples/debug/lib/main.dart index 16aeeeb49..bf84dcc05 100644 --- a/doc/examples/debug/lib/main.dart +++ b/doc/examples/debug/lib/main.dart @@ -10,7 +10,6 @@ import 'dart:ui'; void main() async { Flame.initializeWidget(); - await Flame.util.initialDimensions(); runApp( GameWidget( diff --git a/doc/text.md b/doc/text.md index 1234878cb..3d9c2a92a 100644 --- a/doc/text.md +++ b/doc/text.md @@ -45,16 +45,11 @@ Example usage: TextConfig regular = TextConfig(color: BasicPalette.white.color); class MyGame extends BaseGame { - MyGame() { - _start(); - } - - _start() async { - Size size = await Flame.util.initialDimensions(); - + @override + Future onLoad() async { add(TextComponent('Hello, Flame', config: regular) ..anchor = Anchor.topCenter - ..x = size.width / 2 + ..x = size.width / 2 // size is a property from game ..y = 32.0); } } diff --git a/doc/util.md b/doc/util.md index bd09b6e02..51b5e7361 100644 --- a/doc/util.md +++ b/doc/util.md @@ -25,16 +25,6 @@ This method sets the orientation of the whole application (effectively, also the If a finer control of the allowed orientations is required (without having to deal with `SystemChrome` directly), `setOrientation` (accepts a single `DeviceOrientation` as a parameter) and `setOrientations` (accepts a `List` for possible orientations) can be used. -### `Flame.util.initialDimensions()` - -Returns a `Future` with the dimension (`Size`) of the screen. This has to be done in a hacky way because of the reasons described in the code. If you are using `BaseGame`, you probably won't need to use these, as every `Component` will receive this information. - -**Note**: Call this function first thing in an `async`hronous `main` and `await` its value to avoid the "size bug" that affects certain devices when building for production. - -### `Flame.util.addGestureRecognizer()` and `Flame.util.removeGestureRecognizer()` - -These two functions help with registering (and de-registering) gesture recognizers so that the game can accept input. More about these two functions [here](input.md#Input). - ### Other functions * `renderWhereAt` and `renderRotated`: if you are directly rendering to the `Canvas`, you can use these functions to easily manipulate coordinates to render things on the correct places. They change the `Canvas` transformation matrix but reset afterwards. diff --git a/lib/util.dart b/lib/util.dart index a01170849..a55fed57d 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -2,10 +2,8 @@ import 'dart:async'; import 'dart:ui'; import 'package:flutter/foundation.dart'; -import 'package:flutter/gestures.dart'; import 'package:flutter/services.dart'; -import 'extensions/size.dart'; import 'extensions/vector2.dart'; /// Some utilities that did not fit anywhere else. @@ -92,38 +90,6 @@ class Util { return setOrientation(DeviceOrientation.portraitDown); } - /// Waits for the initial screen dimensions to be available. - /// - /// Because of flutter's issue [#5259](https://github.com/flutter/flutter/issues/5259), when the app starts the size might be 0x0. - /// This waits for the information to be properly updated. - /// - /// A best practice would be to implement there resize hooks on your game and components and don't use this at all. - /// Make sure your components are able to render and update themselves for any possible screen size. - Future initialDimensions() async { - // https://github.com/flutter/flutter/issues/5259 - // "In release mode we start off at 0x0 but we don't in debug mode" - return await Future(() { - if (window.physicalSize.isEmpty) { - final completer = Completer(); - window.onMetricsChanged = () { - if (!window.physicalSize.isEmpty && !completer.isCompleted) { - completer.complete( - (window.physicalSize / window.devicePixelRatio).toVector2()); - } - }; - return completer.future; - } - return (window.physicalSize / window.devicePixelRatio).toVector2(); - }); - } - - /// This properly removes the bind of a gesture recognizer to your game. - /// - /// Use this in order to clear any added recognizers that you have added before - void removeGestureRecognizer(GestureRecognizer recognizer) { - recognizer.dispose(); - } - /// Utility method to render stuff on a specific place. /// /// Some render methods don't allow to pass a offset.