mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 13:08:09 +08:00 
			
		
		
		
	Removing initialDimensions and removeGesture methods (#627)
* Removing initialDimensions and removeGesture methods * Removing wrongly commited folder * PR suggestion
This commit is contained in:
		@ -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
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,6 @@ import 'dart:ui';
 | 
			
		||||
 | 
			
		||||
void main() async {
 | 
			
		||||
  Flame.initializeWidget();
 | 
			
		||||
  await Flame.util.initialDimensions();
 | 
			
		||||
 | 
			
		||||
  runApp(
 | 
			
		||||
    GameWidget(
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								doc/text.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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<void> 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);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								doc/util.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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<DeviceOrientation>` 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.
 | 
			
		||||
 | 
			
		||||
@ -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<Vector2> 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<Vector2>(() {
 | 
			
		||||
      if (window.physicalSize.isEmpty) {
 | 
			
		||||
        final completer = Completer<Vector2>();
 | 
			
		||||
        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.
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user