Changing docs to reflect the refactoring

This commit is contained in:
Erick Zanardo
2019-11-07 18:42:22 -03:00
committed by Erick (CptBlackPixel)
parent a2336b926d
commit dea71c98f3
3 changed files with 60 additions and 43 deletions

View File

@ -263,12 +263,12 @@ A very simple `BaseGame` implementation example can be seen below:
### Input ### Input
`Game` class provides a whole set of methods which can be overridden to get access to touch events. Inside `package:flame/gestures.dart` you can find a whole set of `mixin` which can be included on your game class instance to be able to receive touch input events
__Example__ __Example__
```dart ```dart
class MyGame extends Game { class MyGame extends Game with TapDetector {
// Other methods ommited // Other methods ommited
@override @override

View File

@ -24,10 +24,12 @@ class MyGame extends Game with TapDetector, DoubleTapDetector, PanDetector {
void onTap() { void onTap() {
_paint = _paint == _whitePaint ? _bluePaint : _whitePaint; _paint = _paint == _whitePaint ? _bluePaint : _whitePaint;
} }
@override @override
void onDoubleTap() { void onDoubleTap() {
_paint = _greenPaint; _paint = _greenPaint;
} }
@override @override
void onPanUpdate(DragUpdateDetails details) { void onPanUpdate(DragUpdateDetails details) {
_rect = _rect.translate(details.delta.dx, details.delta.dy); _rect = _rect.translate(details.delta.dx, details.delta.dy);

View File

@ -1,55 +1,70 @@
# Input # Input
The `Game` class has a vast number of methods for handling touch controls, to use it, just override the method you want to use, and that method will start receiving events, below there is the whole list of available methods: Inside `package:flame/gestures.dart` you can find a whole set of `mixin` which can be included on your game class instance to be able to receive touch input events. Bellow you can see the full list of these `mixin`s and its methods:
```dart ```dart
void onTap() {} - TapDetector
void onTapCancel() {} - onTap
void onTapDown(TapDownDetails details) {} - onTapCancel
void onTapUp(TapUpDetails details) {} - onTapDown
void onSecondaryTapDown(TapDownDetails details) {} - onTapUp
void onSecondaryTapUp(TapUpDetails details) {}
void onSecondaryTapCancel() {} - SecondaryTapDetector
void onDoubleTap() {} - onSecondaryTapDown
void onLongPress() {} - onSecondaryTapUp
void onLongPressStart(LongPressStartDetails details) {} - onSecondaryTapCancel
void onLongPressMoveUpdate(LongPressMoveUpdateDetails details) {}
void onLongPressUp() {} - DoubleTapDetector
void onLongPressEnd(LongPressEndDetails details) {} - onDoubleTap
void onVerticalDragDown(DragDownDetails details) {}
void onVerticalDragStart(DragStartDetails details) {} - LongPressDetector
void onVerticalDragUpdate(DragUpdateDetails details) {} - onLongPress
void onVerticalDragEnd(DragEndDetails details) {} - onLongPressStart
void onVerticalDragCancel() {} - onLongPressMoveUpdate
void onHorizontalDragDown(DragDownDetails details) {} - onLongPressUp
void onHorizontalDragStart(DragStartDetails details) {} - onLongPressEnd
void onHorizontalDragUpdate(DragUpdateDetails details) {}
void onHorizontalDragEnd(DragEndDetails details) {} - VerticalDragDetector
void onHorizontalDragCancel() {} - onVerticalDragDown
void onForcePressStart(ForcePressDetails details) {} - onVerticalDragStart
void onForcePressPeak(ForcePressDetails details) {} - onVerticalDragUpdate
void onForcePressUpdate(ForcePressDetails details) {} - onVerticalDragEnd
void onForcePressEnd(ForcePressDetails details) {} - onVerticalDragCancel
void onPanDown(DragDownDetails details) {}
void onPanStart(DragStartDetails details) {} - HorizontalDragDetector
void onPanUpdate(DragUpdateDetails details) {} - onHorizontalDragDown
void onPanEnd(DragEndDetails details) {} - onHorizontalDragStart
void onPanCancel() {} - onHorizontalDragUpdate
void onScaleStart(ScaleStartDetails details) {} - onHorizontalDragEnd
void onScaleUpdate(ScaleUpdateDetails details) {} - onHorizontalDragCancel
void onScaleEnd(ScaleEndDetails details) {}
- ForcePressDetector
- onForcePressStart
- onForcePressPeak
- onForcePressUpdate
- onForcePressEnd
- PanDetector
- onPanDown
- onPanStart
- onPanUpdate
- onPanEnd
- onPanCancel
- ScaleDetector
- onScaleStart
- onScaleUpdate
- onScaleEnd
``` ```
Since many detectors conflict with each other, (for example, you can't register both Vertical and Horizontal drags) by default only the __tap detectors__ are already registered. Many of these detectors can conflict with each other, for example, you can't register both Vertical and Horizontal drags, so not all of then can be used together.
To change that behaviour, you can override methods that enable or disable that gesutre detector for the game, for example, to enable vertical drag detectors, you should override the `useVerticalDragDetectors` to return `true`, all the other detectors have equivalent methods and follow the same logic. All of these methods are basically a mirror from the callbacks available on the [GestureDetector widget](https://api.flutter.dev/flutter/widgets/GestureDetector-class.html), you can also read more about Flutter's gestures [here](https://api.flutter.dev/flutter/gestures/gestures-library.html).
All those methods are basically a mirror from the callbacks available on the [GestureDetector widget](https://api.flutter.dev/flutter/widgets/GestureDetector-class.html), you can also read more about Flutter's gestures [here](https://api.flutter.dev/flutter/gestures/gestures-library.html).
## Example ## Example
```dart ```dart
class MyGame extends Game { class MyGame extends Game with TapDetector {
// Other methods ommited // Other methods ommited
@override @override