mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 00:48:47 +08:00 
			
		
		
		
	This PR fixes #3052 and updates deprecated type references in docs from `RawKeyEvent` to `KeyEvent`. Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
This commit is contained in:
		| @ -26,7 +26,7 @@ To make a `Game` sub class sensitive to key stroke, mix it with `KeyboardEvents` | ||||
| After that, it will be possible to override an `onKeyEvent` method. | ||||
|  | ||||
| This method receives two parameters, first the | ||||
| [`RawKeyEvent`](https://api.flutter.dev/flutter/services/RawKeyEvent-class.html) | ||||
| [`KeyEvent`](https://api.flutter.dev/flutter/services/KeyEvent-class.html) | ||||
| that triggers the callback in the first place. The second is a set of the currently pressed | ||||
| [`LogicalKeyboardKey`](https://api.flutter.dev/flutter/services/LogicalKeyboardKey-class.html). | ||||
|  | ||||
| @ -50,10 +50,10 @@ class MyGame extends FlameGame with KeyboardEvents { | ||||
|   // ... | ||||
|   @override | ||||
|   KeyEventResult onKeyEvent( | ||||
|     RawKeyEvent event, | ||||
|     KeyEvent event, | ||||
|     Set<LogicalKeyboardKey> keysPressed, | ||||
|   ) { | ||||
|     final isKeyDown = event is RawKeyDownEvent; | ||||
|     final isKeyDown = event is KeyDownEvent; | ||||
|  | ||||
|     final isSpace = keysPressed.contains(LogicalKeyboardKey.space); | ||||
|  | ||||
| @ -87,7 +87,7 @@ KeyboardHandlers must only be added to games that are mixed with `HasKeyboardHan | ||||
| After applying `KeyboardHandler`, it will be possible to override an `onKeyEvent` method. | ||||
|  | ||||
| This method receives two parameters. First the | ||||
| [`RawKeyEvent`](https://api.flutter.dev/flutter/services/RawKeyEvent-class.html) | ||||
| [`KeyEvent`](https://api.flutter.dev/flutter/services/KeyEvent-class.html) | ||||
| that triggered the callback in the first place. The second is a set of the currently pressed | ||||
| [`LogicalKeyboardKey`](https://api.flutter.dev/flutter/services/LogicalKeyboardKey-class.html)s. | ||||
|  | ||||
|  | ||||
| @ -27,7 +27,7 @@ Now we can add a new method: | ||||
|  | ||||
| ```dart | ||||
|   @override | ||||
|   bool onKeyEvent(RawKeyEvent event, Set<LogicalKeyboardKey> keysPressed) { | ||||
|   bool onKeyEvent(KeyEvent event, Set<LogicalKeyboardKey> keysPressed) { | ||||
|     return true; | ||||
|   } | ||||
| ``` | ||||
| @ -50,7 +50,7 @@ Now in our `onKeyEvent` method, we can register the key pressed by adding: | ||||
|  | ||||
| ```dart | ||||
| @override | ||||
|   bool onKeyEvent(RawKeyEvent event, Set<LogicalKeyboardKey> keysPressed) { | ||||
|   bool onKeyEvent(KeyEvent event, Set<LogicalKeyboardKey> keysPressed) { | ||||
|     horizontalDirection = 0; | ||||
|     horizontalDirection += (keysPressed.contains(LogicalKeyboardKey.keyA) || | ||||
|             keysPressed.contains(LogicalKeyboardKey.arrowLeft)) | ||||
|  | ||||
| @ -15,7 +15,7 @@ class HardwareKeyboardExample extends FlameGame { | ||||
|   '''; | ||||
|  | ||||
|   /// The list of [KeyboardKey] components currently shown on the screen. This | ||||
|   /// list is re-generated on every RawKeyEvent. These components are also | ||||
|   /// list is re-generated on every KeyEvent. These components are also | ||||
|   /// attached as children. | ||||
|   List<KeyboardKey> _keyComponents = []; | ||||
|  | ||||
| @ -221,9 +221,9 @@ class KeyboardKey extends PositionComponent { | ||||
|   late final InlineTextElement textElement; | ||||
|   late final RRect rect; | ||||
|  | ||||
|   /// The RawKeyEvents may occur very fast, and out of sync with the game loop. | ||||
|   /// The KeyEvents may occur very fast, and out of sync with the game loop. | ||||
|   /// On each such event we remove old KeyboardKey components, and add new ones. | ||||
|   /// However, since multiple RawKeyEvents may occur within a single game tick, | ||||
|   /// However, since multiple KeyEvents may occur within a single game tick, | ||||
|   /// we end up adding/removing components many times within that tick, and for | ||||
|   /// a brief moment there could be a situation that the old components still | ||||
|   /// haven't been removed while the new ones were already added. In order to | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Eli B
					Eli B