mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 08:56:01 +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. | After that, it will be possible to override an `onKeyEvent` method. | ||||||
|  |  | ||||||
| This method receives two parameters, first the | 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 | 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). | [`LogicalKeyboardKey`](https://api.flutter.dev/flutter/services/LogicalKeyboardKey-class.html). | ||||||
|  |  | ||||||
| @ -50,10 +50,10 @@ class MyGame extends FlameGame with KeyboardEvents { | |||||||
|   // ... |   // ... | ||||||
|   @override |   @override | ||||||
|   KeyEventResult onKeyEvent( |   KeyEventResult onKeyEvent( | ||||||
|     RawKeyEvent event, |     KeyEvent event, | ||||||
|     Set<LogicalKeyboardKey> keysPressed, |     Set<LogicalKeyboardKey> keysPressed, | ||||||
|   ) { |   ) { | ||||||
|     final isKeyDown = event is RawKeyDownEvent; |     final isKeyDown = event is KeyDownEvent; | ||||||
|  |  | ||||||
|     final isSpace = keysPressed.contains(LogicalKeyboardKey.space); |     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. | After applying `KeyboardHandler`, it will be possible to override an `onKeyEvent` method. | ||||||
|  |  | ||||||
| This method receives two parameters. First the | 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 | 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. | [`LogicalKeyboardKey`](https://api.flutter.dev/flutter/services/LogicalKeyboardKey-class.html)s. | ||||||
|  |  | ||||||
|  | |||||||
| @ -27,7 +27,7 @@ Now we can add a new method: | |||||||
|  |  | ||||||
| ```dart | ```dart | ||||||
|   @override |   @override | ||||||
|   bool onKeyEvent(RawKeyEvent event, Set<LogicalKeyboardKey> keysPressed) { |   bool onKeyEvent(KeyEvent event, Set<LogicalKeyboardKey> keysPressed) { | ||||||
|     return true; |     return true; | ||||||
|   } |   } | ||||||
| ``` | ``` | ||||||
| @ -50,7 +50,7 @@ Now in our `onKeyEvent` method, we can register the key pressed by adding: | |||||||
|  |  | ||||||
| ```dart | ```dart | ||||||
| @override | @override | ||||||
|   bool onKeyEvent(RawKeyEvent event, Set<LogicalKeyboardKey> keysPressed) { |   bool onKeyEvent(KeyEvent event, Set<LogicalKeyboardKey> keysPressed) { | ||||||
|     horizontalDirection = 0; |     horizontalDirection = 0; | ||||||
|     horizontalDirection += (keysPressed.contains(LogicalKeyboardKey.keyA) || |     horizontalDirection += (keysPressed.contains(LogicalKeyboardKey.keyA) || | ||||||
|             keysPressed.contains(LogicalKeyboardKey.arrowLeft)) |             keysPressed.contains(LogicalKeyboardKey.arrowLeft)) | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ class HardwareKeyboardExample extends FlameGame { | |||||||
|   '''; |   '''; | ||||||
|  |  | ||||||
|   /// The list of [KeyboardKey] components currently shown on the screen. This |   /// 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. |   /// attached as children. | ||||||
|   List<KeyboardKey> _keyComponents = []; |   List<KeyboardKey> _keyComponents = []; | ||||||
|  |  | ||||||
| @ -221,9 +221,9 @@ class KeyboardKey extends PositionComponent { | |||||||
|   late final InlineTextElement textElement; |   late final InlineTextElement textElement; | ||||||
|   late final RRect rect; |   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. |   /// 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 |   /// 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 |   /// 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 |   /// 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